No module named 'matplotlib' Python - python

I am very new to programming so bear with me.
I am trying to import matplotlib . I have matplotlib already on my computer. When I
import matplotlib.pyplot as plt
I get
ModuleNotFoundError: No module named 'matplotlib'
I have tried to uninstall and reinstalled matplot lib using pip and pip3 multiple times. When I uninstall I get this and then reinstall I get this:
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\...
I have also tried uninstalling and reinstalling python but that doesn't seem to do anything.
What can I do to fix this? I am using the most recent version of Python.

If you have multiple python editors, make sure you installed matplotlib with the pip.exe from the python editor you are trying to import matplotlib.pyplot in.
Make the pip.exe you are using in a folder called Scripts is in the folder that contains to python editor of interest.
For example, the pip.exe from Pycharm could be 'C:\Users\User\jetbrains\AppData\Roaming\Python\Python37\Scripts', while the pip.exe from spyder could be 'C:\Users\User\Anaconda3\Scripts'.

Related

Importing python modules in vscode

Recently downloaded vscode on macOS, but I seem unable to import any python modules. I've made sure I'm using a python3 interpreter but can't find the problem. For example:
import numpy as np
returns
ModuleNotFoundError: No module named 'numpy'
and similarly for any other modules:
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I have downloaded homebrew although I don't understand what it is (I'm a physicist not a programmer) and so far spent a few hours trying to figure it out. Any help would be great.
Those two modules are third-part modules that need to be downloaded. The easiest/most common way to download is to use pip, which is a python module that should have come with your python install.
From the command line, run a python3 -m pip install numpy matplotlib. That will call python using the module pip, with the pip command 'install numpy maplotlib' (you can call them one-at-a-time if you like).
Once they are installed, you should be able to import them as you attempted above.
This happened to me before when I tried to download the flask module,all I did was restart my vs-code and everything was working

ModuleNotFoundError using pip

I have installed the module alpha_vantage using pip. In CMD writing import alpha_vantage does not show an error message, so I assume it is installed properly.
However, when trying to import alpha_vantage in a python program I get this error: "ModuleNotFoundError: No module named 'requests'". I assume the issue is due to the location of the module.
The project is located here:
C:\Users\M\Documents\Python\Investering.
I tried placing the module here by pip: C:\Users\M\Documents\Python\Investering\modules\alpha_vantage
Note pip did not install the module there I simply copied the module folder and placed them in the project folder.
Is it possible to simply copy and paste module folders in other projects? Or how am I supposed to make python acknowledge the module?
The module was installed here:
C:\Users\M\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\alpha_vantage
I'm quite new to python. I have tried adding to sys.path the folder where the module was installed, but it did not seem to help.
Thanks for any help.
Edit: I tried pip install requests and it produced this:
Requirement already satisfied: requests in c:\users\martin\appdata\local\programs\python\python38-32\lib\site-packages
Someone mentioned running: "pip install foo"
It, however, produces this error message:
ERROR: Could not find a version that satisfies the requirement foo (from versions: none) ERROR: No matching distribution found for foo
I am using PyCharm.
I found my error. I had installed python from the website, but had unknowningly installed the 32 bit version, and a 64 bit version. I uninstalled all my python versions and pycharm. Then I reinstalled everything. Now I could easily make the module work. Thanks for the pointers.

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

Installing matplotlib on windows 10 python 3.6

HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python Community\Python 3.6.1\lib\decimal.py", line 3 in , from decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
and when I enter an interactive shell:
import matplotlib
I get a ModuleNotFoundError
I have tried a matplotlib-2.2.2-cp36-cp36m-win32.whl and matplotlib-2.2.2-cp36-cp36m-win_amd64.whl both give the same error.
Could someone please let me know how to fix this?
I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'.
The file was stopping the install so I renamed it and reinstalled matplotlib and it now works.
Sorry but this was not obvious to me !
Try running cmd as administrator inside the python directory. Then execute:
pip3 install matplotlib-2.2.2-cp36-cp36m-win32.whl
Also make sure that you have all dependencies installed.
The code seems very specific and something may not be supported any more.
You could first uninstall the current version using:
pip uninstall matplotlib
and then try installing matplotlib as follows:
pip install matplotlib
providing that you have admin rights to do so.
Then you can import as: import matplotlib.pyplot as plt
It seems like you are installing the package on Python 2.
Try installing the library using:
py -3 -m pip install --user matplotlib
Assuming you are using Windows.
Try doing as below:
python -m pip install --user matplotlib

unable to run matplotlib

on 64bit win 7, I installed all of compatible versions of setuptools, numpy, python-dateutil, pytz, pyparsing and six in addition to matplotlib. I did this by downloading source into a folder, and installing from source ... for example,
python setup.py install
finally, I installed python matplotlib by,
cd matplotlib
python setup.py build
python setup.py install
I tested matplotlib by running python from my windows powershell, and typing import pylab I got error:
ImportError: error importing numpy: you should not try to import numpy from its source ...
I found a stackoverflow question that addressed this, leading answer was to change working directory from the directory where numpy lives.
I changed the working directory to another folder in my drive, again ran python from my interpreter, typed import pylab and received this error:
ImportError: NO module named numpy"
I am now at a loss. It either refuses to import numpy, or says it doesn't exist? But it knew it existed earlier?
Ive been looking for a solution for more than three hours now, am stumped. Apologies in advance if this question seems too noob.
finally, I am open to trying a different module if it would be easier. I only want to plot some data.

Categories

Resources