Im trying to use huggingface transformers library in my python project. I am a first time python programmer, and I am stuck on this error message, even though tensorflow has been installed on my machine:
>>> from transformers import pipeline
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
I have discovered that tensorflow does not exist, even though I have installed it via pip. I have tried uninstalling it and reinstalling it, and but when I try to import the package, it just comes back as a ModuleNotFoundError
>>> import tensorflow
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import tensorflow
File "C:\Users\######\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
ModuleNotFoundError: No module named 'tensorflow.python
I have tried uninstalling and re-installing using pip and conda. I even tried installing pytorch using the same methods. It always says that the package was succesfully installed, and yet the error persists.
I am using Python 3.9 and my OS is Windows 10. I dont know what I am doing wrong. But I know that a solution will definitely not be to uninstall and reinstall a package.
Pip version (pip -V):
pip 21.1.3 from c:\users\######\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)
Python version (python -V):
Python 3.9.5
Python path list
I tried comparing the output of sys.path with the output of pip -V.
The closest path I saw for the pip -V path is down at the bottom, however I did not find the exact directory.
>>> import sys
>>> sys.path
['', 'C:\\windows\\system32', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\\python39.zip', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\\DLLs', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\\lib', 'C:\\Users\\######\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0', 'C:\\Users\\######\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0', 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\\lib\\site-packages']
Closest path:
C:\Users\######\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages
From comments
You have multiple python interpreters installed, that is why
installing stuff does not show in your python interpreter, use pip -V and compare it to the python version that appears in the interpreter. Remove one and use only one then your issue will be
resolved (paraphrased from Dr.Snoopy)
Related
I have installed OpenCV with the command pip install opencv-contrib-python and when I run the command pip list I see opencv-contrib-python has been installed and yet import cv2 does not work for me and it throws
Traceback (most recent call last):
File "\[filename here\]", line 1, in \<module\>
import cv2
ImportError: No module named cv2
and I have tried uninstalling and reinstalling OpenCV and it still does not work. I tried different development environments like Pycharm and visual studio code. I also have my pip upgraded and my OpenCV is version 4.5.5 which is the latest version. I have tried using python 3.10 and 3.7 but the same error still shows. I have also tried using
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages')
which was recommended in some answers and I have tried just installing opencv-python and using that and the same error still shows. I checked and I have cv2 in
my folder
but despite this, it keeps showing no module named cv2 every time I try to run import cv2
I use macOS Monterey version 12.2.1 and for my terminal, I use Darwan OS which is a Linux distro.
I tried:
pip install opencv-python
pip install opencv-contrib-python
putting this at the first lines of code:
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages')
You have to use python2.7. As the manual says: "Currently, only the Python 2 version of the cv2 module is built and included in the latest release."
You can only use python3 if you manually build from source code.
I was working with Python 3.7 and OpenCV 4.2 in Pycharm IDE (Windows10). The system environment variables were changed by one of my co-workers by accident (we don't know what happened exactly). Then I found that my code did not work with this error!:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
Then I used this command:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-python
All of them executed successfully, but when I write import cv2 the above error is appeared. By the way, the system knows command Python, it shows the right path to the python.exe. Moreover, commands like import numpy works correctly! How can I fix this problem?
I found the answer! There was an extra cv2.py file in site-packages/cv2 path. So, I removed it and the code worked
I am trying to install Pytorch via pip on ubuntu 18.04.I have python 3.6 and my laptop is HP-Pavilion notebook 15
The installation seems to be right because i get the message:
Installing collected packages: torch, torchvision Successfully
installed torch-1.3.1+cpu torchvision-0.4.2+cpu
i run the verification code and it is ok
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
However, when i close the terminal or reboot and try to run he same code i get the error:
Traceback (most recent call last):
File "torch.py", line 2, in
import torch
AttributeError: module 'torch' has no attribute 'rand'
How are you executing the python script? Which python are you using? Maybe you installed the package in a different python version?
Try to set alias to the python you want to use:
alias python=/usr/local/bin/python3.6
Then pip install the package with that python alias you will always be using.
python pip install <package name>
Python now will install the package in the python files with the alias python - heading to files: /usr/local/bin/python3.6
Let me know if the error still occurs!
Install pytorch using pip through the below command:
pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
for any reference go through the official website of pytorch.
Change your file .py to another name, you named torch.py when you import torch it will call ur torch.py
I'm trying to install NUMBA on a mac machine (10.12.6).
I've tried with CONDA:
conda install numba
I'm getting this:
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /Users/lefaa/miniconda2:
#numba 0.35.0 np113py27_6
This seems good, however when I try (using python 2.7):
python -c "from numba import jit"
I'm getting that the numba module isn't installed:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numba
Do I have to configure something else?
It is likely that your path is not set up correctly and the python that conda installed numba into is not the one you are running. If you run which python you should get the one that's in your miniconda2 if everything is working properly. If you get a different python executable then you probably need to set your PATH environment variable. See:
https://conda.io/docs/user-guide/install/index.html#installing-conda-on-a-system-that-has-other-python-installations-or-packages
I solved the issue. Indeed, when installing with conda, conda installs the target package in python associated to conda (i.e, in this python '/Users/lefaa/miniconda2/bin/python'). So to import numba, it is necessary to lunch the python of miniconda.
However, to install numba on the main python (python2.7), one solution will be to install like this '/usr/local/bin/pip2.7 install numba'.
Installed python 3.5.2 and also tensorflow using pip command but getting error while importing tensorflow package.
Used command as import tensorflow as tf to import tensorflow. But got error as;
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'tensorflow'
How can I rectify this error?
Can I get answer for this as soon as possible..
Are you running on a IDE or ipython or Jupyter?
If yes, it's likely the IDE is using a different python such as virtualenv. It's possible there are multiple pythons installed in your system.
Open cmd and try the following
$ where python
$ python -c "import tensorflow"
Make sure the path you get is same as the installation path.
If there is still an error, compare with this path
$ where pip
It's possible your system is using a different python path if there are multiple python.