Cannot import torch Error loading ..\caffe2_nvrtc.dll" or one of its dependencies - pytorch

I am on a Windows 10 64 bit system.
Pytorch for cuda has been working successfully for some time.
Today I tried to upgrade to the latest version of Pytorch (1.13) using
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
Now I cannot import torch. I get the error:
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\alan\anaconda3\lib\site-packages\torch\lib\caffe2_nvrtc.dll" or one of its dependencies.
I have tried both in a Jupyter notebook and in the Spyder IDE.
I have tried completely removing Anaconda and reinstalling afresh and then reinstalling Pytorch with no success.
I do not believe I have any other versions of python installed.
The offending dll (caffe2_nvrtc.dll) does seem to be in the file location specified.
I have found various similar problems reported but they all date back to 2020 or earlier and none of them seemed to have a satisfactory solution.
Can anyone point me in the correct direction

I still do not understand why using conda did not work but I tried again using pip
and that did work

I experienced the same problem as yours today.
It turns out that when I use the anaconda prompt then the problem disappears.
Anaconda prompt could do it
Then I speculated that the only difference between these two scenarios is that when I use the anaconda prompt, I use the base anaconda environment, probably somehow the conda environment in spyder is not activated.
So the solution is to open the spyder in anaconda prompt like this:
Then it works.
This picture will tell you the cause for the problem.
problem...

Related

How do I fix a keras error for a plaidbench keras test?

I am trying to install plaidml-keras so I can use non-Nvidia GPUs with Keras in python/jupyter. After clearing several other hurdles I get as far as:
plaidbench keras mobilenet
but it errors twice
ImportError: cannot import name 'object_list_uid' from 'keras.utils.generic_utils' (/Users/me/sprinthive/src/notebooks/nbenv/lib/python3.7/site-packages/keras/utils/generic_utils.py)
File "/Users/me/sprinthive/src/notebooks/nbenv/lib/python3.7/site-packages/plaidbench/frontend_keras.py", line 321, in __init__
raise core.ExtrasNeeded(['plaidml-keras'])
plaidbench.core.ExtrasNeeded: Missing needed packages for benchmark; to fix, pip install plaidml-keras
This is in spite of already having plaidml-keras installed:
pip freeze | grep plaid
plaidbench==0.6.4
plaidml==0.6.4
plaidml-keras==0.6.4
[I am using 0.6.4 to make it work on macOS 10.13 High Sierra]
How can I resolve the above errors?
Thanks!
I worked this out by creating a virtual environment with Anaconda. Beware that i am working on Windows, so this might not be a solution for your problem. If i had to guess, something was installed by me before that causes a python package problem. I think this is related to the tensorflow library, but i haven't dug into that. I would recommend trying out a fresh virtual environment on your Mac, where you install the plaidml package. The error Message before was exactly the same.

Jupyter kernel keeps crashing -- "No module named prompt_toolkit.formatted_text"

I cannot get Jupyter Notebook running -- it keeps restarting the kernel and giving the error message,
ImportError: No module named 'prompt_toolkit.formatted_text'
A few threads online say it is an issue with ipython versioning which can be fixed by a rollback, but that hasn't worked for me.
Here are my current versions of relevant packages:
conda==4.5.11
ipykernel==4.10.0
ipython==6.5.0
ipython-genutils==0.2.0
ipywidgets==7.4.2
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==4.1.1
jupyter-core==4.4.0
jupyter-kernel-gateway==2.1.0
jupyterlab==0.34.12
jupyterlab-launcher==0.13.1
notebook==5.7.0
prompt-toolkit==1.0.15
Any help you can provide would be great. Thanks!
I did have the same issue with Jupyter Notebook. Point is that ipython requirement specific version of prompt-toolkit. In my case, I have ipython 7.2.0 which required prompt-toolkit <2.1.0,>=2.0.0
I just added prompt-toolkit<2.1.0,>=2.0.0 to my requirements.txt to solve this problem.
Try to run pip install prompt_toolkit and see which version of prompt_toolkit need in your project.

Pycharm, opencv fails to load dll, works on prompt

After installing miniconda with python 3.7 I do the following:
conda create --name opencv_test python=3.7
conda activate opencv_test
conda install -c anaconda opencv
Then to test the environement I do:
python
>>> import cv2
>>> exit()
Everything goes according to plan
Then if I launch PyCharm or vs code, set my new environment as the interpreter and create a simple file that contains only
import cv2
On launch I get:
ImportError: DLL load failed: The specified module could not be found.
What I learned from the internets:
This, this and this, all those posts refer to a problem that seems similar, the difference being that the issue for me only happens when using IDEs
What I tried before posting here:
Recreating the environment multiple times switching channels.
As it seemed to be a path issue, I added the paths which contained opencv dll to the environment paths in PyCharm settings one at a time
What I just tried after spending a considerable amount of time creating this post:
conda update conda
This weirdly downgrades python to 3.6
conda create --name opencv_test_2 python=3.6
conda activate opencv_test_2
conda install -c anaconda opencv
This seems to fix all the issues but:
I don't know what just happened and why the issue only appeared on IDEs
I'd like to use python 3.7
So in short, why when using python 3.7 and PyCharm I seem to be unable to import opencv even if it works on command line?
Thanks in advance.

Anaconda3 libhdf5.so.9: cannot open shared object file [works fine on py2.7 but not on py3.4]

I just tried to use pd.HDFStore in IPython Notebook with a Python 3 kernel (Anaconda 2&3 on Ubuntu 14.04)
import pandas as pd
store = pd.HDFStore('/home/Jian/Downloads/test.h5')
but it throws the following error
ImportError: HDFStore requires PyTables, "libhdf5.so.9: cannot open shared object file: No such file or directory" problem importing
I initially thought it's because pytables is somehow missing, but when I check $source activate py34 and $conda list, pytables 3.2.0 is already installed under anaconda python3 environment.
Also, if I switch to Python 2, for example, $source activate py27 and start ipython notebook, it works properly and no import error is thrown.
I guess that I must miss something for configuring pytables under anaconda python 3 env, but I cannot figure it out. Any help is highly appreciated.
Update:
I just tried on a fresh install of Anaconda3-2.3.0-Linux-x86_64 from official website and it ends up with the same error. When I try $locate libhdf5.so.9 in command line, nothing shows up.
This is a known issue that we are working on. When it is fixed, conda update --all will update the libraries and fix the issue.

ImportError: cannot import name '_imagingtk'

I am using Anaconda with python 3.4 and I am not able to get all the pillow packages I need I am afraid on Windows 8.1.
I installed pillow via the Anaconda console with:
pip install pillow
which lead to:
The following packages will be UPDATED:
conda: 3.10.0-py34_0 --> 3.10.1-py34_0
conda-env: 2.1.3-py34_0 --> 2.1.4-py34_0
pillow: 2.7.0-py34_0 --> 2.8.1-py34_0
pip: 6.0.8-py34_0 --> 6.1.1-py34_0
setuptools: 14.3-py34_0 --> 15.0-py34_0
Now, in the spyder IPython console I start with: import tkinter, from PIL import ImageTk I have no errors here, but when executing ImageTk.PhotoImage(file='a.jpg') I receive an error, telling me: ImportError: cannot import name '_imagingtk'
What did I miss?
I know this is not a complete answer, but I have had the same problem and spent a day trying to figure it out...
Here is a small subset of things I tried yesterday to the best of my weak memory...
-Tried upgrating to the latest Python environment using anaconda (tip: you can create one using
conda update conda
conda update anaconda
(I think that's it, but may have tried to make sure for key packages explicitly etc.)
-Tried using Python 3.3 environment using anaconda (tip: you can create one using
conda update conda
conda create -n py33 python=3.3 anaconda
activate py33
-Tried using PythonWin instead of anaconda (that one took some time, had to install packets like numpy manually...)
-Tried updating / downgrading / installing/ uninstalling all kinds of different variations of Pillow, PIL, etc....
-Tried using opencv instead of PIL, though did not try to write my own components...
-Tried manually copying Tcl/tk and a few others to the lib directory as suggested by some posts
-Tried using import tkinter instead of Tkinter, using import Image vs. form PIL import Image (and in general taking Image from PIL, or opencv, or Tkinter) and a lot of other similar changes to the point it fell I was doing silly things
-...
At the end, I googled a few pages about GUIs in python, and now I am using wx... I had to run
conda install wxpython
and that was it. I have to say that after all this, I am presently surprised by how easy it was to make it work, here is a code example...
You need tcl/tk library.
Install them using apt-get
Do sudo apt-get install tk8.6-dev tcl8.6-dev
--Reference.

Resources