I have recently installed the Anaconda distribution of Python. I then inserted the following line into my .bashrc file:
export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH
So, there are now two python binary files: one in /usr/bin/, and one in /home/karnivaurus/Libraries/Anaconda/bin.
I also have a python script, which attempts to import a module named caffe, with the line import caffe. Now, if I run python caffe from the terminal, the script runs fine. However, if I open the script in PyCharm, and set the interpreter to be /home/karnivaurus/Libraries/Anaconda/bin/python, I get the following error:
ImportError: No module named caffe
Based on all this, I have two questions....
If I run the python command from the terminal, which binary file would it execute? The one in /usr/bin, or the one in /home/karnivaurus/Libraries/Anaconda/bin? My intuition is that it runs the first one, due to the discrepancy in behaviour with PyCharm. In that case, how can I force my system to use the Anaconda version?
If I install a new package, for example pip install caffe, then where will it be installed to? Will it be installed to /usr/local/lib/python2.7/site-packages, or to /home/karnivaurus/Libraries/Anaconda/pkgs? How can I be sure that my python command will know where to find the new package?
Thank you!
Answer to 1:
Based on your example: export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH the /home/karnivaurus/Libraries/Anaconda/bin comes first, so the python from there should be the one to be executed.
But the definite answer depends on result of running: which python.
Answer to 2:
In Anaconda, use conda instead of pip to install packages. When you install using pip install caffe you'll be installing to /usr/local/lib/python2.7/site-packages.
Use conda install caffe to install to /home/karnivaurus/Libraries/Anaconda/pkgs.
Above two answers explain why even if you pip install spam package, python would say ImportError: No module named spam. Essentially you install to ordinary Python, but you attempt to import in Anaconda's python.
Related
I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.
I was trying to install the python chess module and kept getting the same error: ModuleNotFoundError: No module named 'chess'
I looked at some other code and noticed the same problem of not importing the module even though it worked before (in this case it was from sklearn.model_selection import train_test_split).
I figured the problem was that I put all my code in a new folder. Once I took out all of my code from this folder it was able to work, but the chess module still didn't. This made me think that it must be an issue with the path.
Since I use quite a few folders in order to organize my work. How do I fix this?
I don't want to take out all of my code from every folder I have.
I am using VSCode, and I have already installed the chess module, several times, using pip, pip3, python -m install pip, conda, in the command prompt, terminal in VSCode, and miniconda.
So it is not an installation problem.
You can install module manually,
pip install python-chess
Run this command in virtual environment, this will install python chess module
I'm using Python 3.6 on Windows 7.
I have a script that uses standard python packages.
The script run fine from IDLE.
It used to run fine from Windows command too, but not anymore.
I don't know why. It complains about missing package like:
, line 4, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
The path looks ok (I've added all path found from IDLE / Path Browser):
PATH=C:\Users\olivier\AppData\Local\Programs\Python\Python36\lib\site-packages;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Lib;C:\Users\olivier\AppData\Local\Programs\Python\Python36\DLLs;C:\Users\olivier\AppData\Local\Programs\Python\Python36\python36.zip;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\olivier\AppData\Local\Programs\Python\Python36\;C:\Users\olivier\AppData\Local\GitHubDesktop\bin
Any idea?
Thanks
I had the same problems. Did you try to install it through pip and did you try to install on the strict path by using pip install --target="..." for e.g "pip install --target=C:\U2\UV\python\Lib\site-packages geopy" and pasting it in python console?
Also look at this post: Install a module using pip for specific python version
These two points can help you to solve the problem as per my knowledge.
Are you using two Python versions?
Check the Environmental Variables and if everything is fine there, it's better to uninstall and reinstall it again. use pip for installing and uninstalling
I try a python code for signature recognition, and there is an import ffnet module (from ffnet import mlgraph, ffnet), but I got an error when I run it.
The error is:
ModuleNotFoundError: No module named 'ffnet'
I have install the module, but still got that error
Help me to fix this :)
You need to make sure that it is correctly installed. The error message means directly "You haven't installed it properly".
Depending on what Python version you're using, you should have a package manager called pip that takes charge of installing and uninstalling modules. Try:
pip2 install ffnet if you have Python 2.
pip3 install ffnet if you have Python 3.
Alternatively, you may have installed Python using Anaconda. In this case, use conda install ffnet. In all cases, run the proposed commands in a terminal.
However, it would be quite useful to have more details about your problem (what OS do you have, how and where did you install Python, what version do you have).
There is great chance that the pip (i suppose you use pip for installation, the idea is identical) you use to install ffnet is not correspond to the python you are using. Maybe a virtualenv is running, or you using python 2 but ffnet is installed with pip3
My suggestion:
- Run which pip. Run which python. Compare the results if anything seem wrong (python2 pip3 for example). Try to run python2 and pip2 instead of python and pip
- If the above suggestion doesn't work, you should try to recheck your PATH: Find the pip correspond to your current python (usually within the same dir) and export PATH=/path/to/THAT/pip/:$PATH
- If the problem still persist, I suppose your pip file's first line (for specifying its corresponding python path) has been modified without your awareness. You will have to manually edit it to something like #!/usr/bin/python3
Hope this help!
I've been following sentdex's python beginner series. I was doing well enough until I had to path python so I could use pip. I did that, and tried installing a few whl files, cx_Freeze and PIL.
It said everything was installed correctly and they're in libs/site packages but whenever I try to draw from them I get an error saying
ModuleNotFoundError: No module named 'cx_Freeze' (or PIL or whatnot).
Am I getting the wrong version?
EDIT: So I thought the problem was that the python shell was in a different location than the rest of my python install, which is not the case, I just only saw part of the path. I re-ran the script in the command prompt version of python.exe and I got no errors. What the hell is going on
you probably run a different python or pip then the one you expect. It happens with me often. To avoid such an issue use:
python -m pip install Pillow
python -c "from PIL import Image; print(Image)"
by calling the same python executable you avoid problems using a pip that belongs to a different python install.
You can also use:
python `which pip` install Pillow