Matplotlib works in my IDE, but not through cmd? - python

I've installed matplotlib through pip, and it runs perfectly when I use it in PyCharm. However, when I run my Python file through cmd, I get the following error message:
ModuleNotFoundError: No module named 'matplotlib'
I have installed other modules the same way, and those have no problems running in PyCharm or in cmd.
Matplotlib is installed under:
C:\Users\David\appdata\local\programs\python\python38-32\lib\site-packages
Something I noticed - perhaps the root of the problem - Is that Python seems to be installed in 2 places:
C:\Users\David\AppData\Local\Programs\Python\Python38-32\python.exe
The path above is also the path to my Python Interpreter on PyCharm.
and
C: \Users\David\AppData\Local\Microsoft\WindowsApps\python.exe
Python version 3.8.5
Windows 10
Thanks in advance!

try running the command pip install matplotlib in your cmd. It works for me.

Related

Issues importing libraries

I just installed Python and Visual Studio code on a Windows 10 machine.
I have imported i few libraries using pip. When I did that I got a warning saying I needed to add a certain folder to PATH which I did.
Using the cdm, I can start a python environment and import matplotlib without issues. I note that my Python version in the cmd is Python 3.9.7
When doing the same thing in Visual Studio code I get the following error message
ModuleNotFoundError: No module named 'matplotlib'
I also notice that my Pyhton version in Visual Studio Code is Pyhton 3.9.1.
I dont really understand what is going on here since I've never had this issue before. Usually it "just works"
Thanks
You have 2 versions of python installed. One of them could be a virtual environment. You can diagnose which Python interpreter you are using by running:
import sys
print(sys.executable)
If VSCode you can switch between interpreters; it may take some searching through the options.
In to the visual code terminal, which probably is using your venv (you should see "(venv)" at begin of each row) type:
pip list
and look if you module is installed. Otherwise you can install here or change environment.
You have installed in two python versions Python 3.9.7 and Python 3.9.1 in vs code.Matplotlib was installed in Python 3.9.7 in vscode, but you used python3.9.1 as an interpreter, that’s why it threw No module error. You need to add a virtual environment of Python 3.9.1. Python has a full guide here on how to set virtual environment How to add virtual environment
then you change python interpreter
matplotlib has been installed in the python 3.9.7 while not in the python 3.9.1.
So you can try to switch the python version in the VSCode to the python 3.9.7 or install the matplotlib in the python 3.9.1.
You can click here to switch the environment. And you can refer to the official docs for more methods and details.
Or you can install the matplotlib package again in the VSCode terminal.

Python: ModuleNotFoundError despite module being installed

I made a module named 'calc' and installed it using the following command in cmd:
py -3 -m pip install calc-2.1.tar.gz.
I can import the module and use it when I run python in cmd.
Yet, anywhere else, it doesn't work. Both IDLE and Anaconda raise ModuleNotFoundError.
The same goes for other modules I try to install.
By the way, I'm really new to python, so could you please be a bit more specific with the instructions?
Ok, I figured out what the problem was.
I was using different versions of python (3.7 in IDLE, 3.8 in Spyder, 3.9 in cmd) which is why the module installed by cmd didn't work other places.

No module named 'cv2' even though it was successfully installed

I pip installed several packages (opencv, face_recognition, imutils)
They were all successfully installed, but are not recognized
I have a python script named script.py which imports cv2, but when I run it I get the following:
ModuleNotFoundError: No module named 'cv2'
I tried using pip list command to see the packages I have installed, but the packages I installed are not showing as you can see below.
I run pythonVersion.py to check my python version, it says it's using 3.8.2 which is where my packages are stored, as shown below.
I tried using #!/Users/Khuzama/opt/anaconda3/lib/python3.8 (the path of my packages) in my script, but still the same issue.
I am using jupyter notebook (anaconda navigator)
It is most probably the python environment you installed the packages are not the one you are currently referring to.
Try seeing the output of
which python
if this doesn't point to the anaconda one, then navigate to Users/Khuzama/opt/anaconda3/lib/python3.8 and run your script from there. Alternatively you can link the python from anaconda as the main python for your system

ModuleNotFoundError from Visual Studio after installing Python modules with "pip" on the command line

I am trying to install modules like tkinter, bs4 and numpy.
I use cmd and pip to install them, and it says that everything is installed fine.
When I am using Visual Studio code it says
ModuleNotFoundError: No module named '....'
How can I find out if Python and the modules are in the same PATH?
Or what can i do to fix that?
I've tried to reinstall Python, but I get the same error.
Is it just the VSC?
File "c:/Users/Γιώργος Μαργα/Desktop/test.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code.
if vscode not recognize your modules try to reload vscode.
install modules with
python3 -m pip install {new_module}
and then reload your Vs code
make sure to set your Python interpreter within VSCode to the same as the one in your system path pythoninvscode
Ok so i uninstall python and installed it again but this time i checked the box that said add that to PATH or someithng like this.
I also uninstalled python from the windowsstore however when it ry to run a code in VSC it doesnt do anything

ModuleNotFoundError: No module named 'yyy' in Windows Shell

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

Categories

Resources