Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOLVED] Broken installation due to (1) hanging conda command and (2) wrong OpenCV version #6

Open
mcarletti opened this issue Aug 7, 2024 · 2 comments

Comments

@mcarletti
Copy link

mcarletti commented Aug 7, 2024

I had a few problems during the installation steps, specifically:

  1. ⏳ First conda command hangs indefinitely due to impossibility to solve CUDA Toolkit references.
  2. 🥥 It's not possible to import cv2 module due to version mismatching. This prevents to run the demo.

I've solved each issue as following.
Hope this helps. Cheers!


CUDA Toolkit installation hangs indefinitely
The command conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge does hang indefinitely.

Fix 1 (naive solution)
I removed the cudatoolkit=11.1 -c conda-forge part to let Pytorch install the requirements by itself.

Fix 2 (edit, as suggested here)
Avoid a direct reference to cudatoolkit by using a combined Pytorch+CUDA versioning: pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html


🥥 OpenCV broken version

I wasn't able to run the demo, due to a broken cv2 import. This is the error:

Error processing line 1 of /home/marco/anaconda3/envs/poco/lib/python3.8/site-packages/distutils-precedence.pth:

  Traceback (most recent call last):
    File "/home/marco/anaconda3/envs/poco/lib/python3.8/site.py", line 177, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named '_distutils_hack'

Remainder of file ignored
Traceback (most recent call last):
  File "demo.py", line 21, in <module>
    import cv2
  File "/home/marco/anaconda3/envs/poco/lib/python3.8/site-packages/cv2/__init__.py", line 190, in <module>
    bootstrap()
  File "/home/marco/anaconda3/envs/poco/lib/python3.8/site-packages/cv2/__init__.py", line 184, in bootstrap
    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
  File "/home/marco/anaconda3/envs/poco/lib/python3.8/site-packages/cv2/__init__.py", line 37, in __load_extra_py_code_for_module
    py_module = importlib.import_module(module_name)
  File "/home/marco/anaconda3/envs/poco/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/marco/anaconda3/envs/poco/lib/python3.8/site-packages/cv2/typing/__init__.py", line 171, in <module>
    LayerId = cv2.dnn.DictValue
AttributeError: module 'cv2.dnn' has no attribute 'DictValue'

Fix
As mentioned in this issue, changing opencv-python version to opencv-python==4.8.0.74 fixed the problem.

@saidwivedi
Copy link
Owner

Thank you your interest :)

  1. If for some reason, conda indefinitely hangs for you, I would not recommend removing cudatoolkit=11.1 -c conda-forge, since it might install pytorch for different CUDA version. Instead, I would run this:
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
  1. As mentioned in the requirements.txt (see here), did you install the 4.5.5.64 version of opencv-python?

@mcarletti
Copy link
Author

First of all, thanks for the hint on Pytorch+CUDA 👍🏼

I tried creating the enviroment a second time, however the process needs a little help because of the following issues:

  1. The installation of the required modules via requirements.txt updates Pytorch to 2.4.0+cu121. To fix this and keep 1.8.0+cu111, I need to re-run the updated conda command you mentioned, that is after pip. To me, this issue suggests untracked incompatibilities among the packages.

  2. Regarding opencv-python, I succesfully installed the correct module via the requirements file, and I confirm the version is the one written in the file, that is 4.5.5.64. This is the output of pip freeze | grep opencv:

Error processing line 1 of /home/marco/anaconda3/envs/poco2/lib/python3.8/site-packages/distutils-precedence.pth:

  Traceback (most recent call last):
    File "/home/marco/anaconda3/envs/poco2/lib/python3.8/site.py", line 177, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named '_distutils_hack'

Remainder of file ignored
opencv-python==4.5.5.64
opencv-python-headless==4.10.0.84

As you can read, there is something weird happening when accessing the environment.

  1. The above error related to distutils appears every time I open a Python terminal in this "fixed" environment.

Despite the right version of the modules, the error mentioned in my initial message is still there and I'm not able to run your code, even after following your Pytorch+CUDA fix and (1) forcing the version of Pytorch 🤷🏼

As of now, updating Pytorch and CUDA to 2.4.0+cu121 and OpenCV to 4.8.0.74 solved the installation, at least for the demo script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants