Um... I wanted to import matplotlib in Python IDLE, but it said
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
I've already tried pip thing and the conda thing in terminal.
It said
# All requested packages already installed.
# packages in environment at /Users/Dan/anaconda:
Then! what's the problem here?
You may have installed Matplotlib to Python 2.7 and not Python 3.6. To install it to Python3 you need to use pip3:
pip3 install matplotlib
Then open python3.6 from your terminal (not idle) and try importing matplotlib from there. This way you can use any text editor you wish, and run your code from the terminal.
I had the same issue using the same command in IDLE. I just figured it out. go to your terminal and enter:
pip3.6 install matplotlib
I was using pip3 instead of pip3.6
Related
I'm using python 2.7.18 on Windows, and i saw that ipaddress library was exclusively for python3 so i installed py2-ipaddress using pip. When i ran pip list into cmd, it shows py2-ipaddress as installed, but when i try import ipaddress into a python file i get this
Traceback (most recent call last):
File "C:/Users/x/Downloads/main (2).py", line 1, in <module>
import ipaddress
ImportError: No module named ipaddress
Why i can't import it?
EDIT :
Actually, ipaddress works fine on python2.7.x, or it should, i installed now ipaddress using pip install ipaddress, it shows as installed when running pip show ipaddress but i still can't import it
#Matthias was right. It seems that my pip doesn't work properly, or i don't know how to use it properly. One quick fix, if you're running pycharm or any IDE with a built-in terminal is to install the module via IDE's terminal using pip install <module>.
I have Python 3.7.3 installed and installed numpy, scipy via pip (cmd -> python -m pip install --user numpy scipy) and am able to import numpy, scipy if I use an admin command prompt to import both numpy and scipy. However, if I don't use an admin cmd prompt, or try to import scipy from the Python shell, I receive traceback errors like the following:
>>> import numpy
>>> import scipy
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
Does this traceback error come from not installing scipy in a certain way? Thanks for the help in advance.
When doing checking pip and python versions in cmd, here's my output:
pip --version
pip 19.1 from c:\program files\python37\lib\site-packages\pip (python 3.7)
python --version
Python 3.7.3
Add the location of your python scripts to the Path in Environment Variables.
C:\Users\User_Name\AppData\Roaming\Python\Python37\Scripts
You mentioned that you've already installed the packages. And the packages are stored in the site-packages file inside Python37 folder. So the error must be because you didn't add these to the path.
I am trying to run the PyCharm profiler but I get the following error message:
Traceback (most recent call last):
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 164, in <module>
profiler.run(file)
File "/home/b3053674/ProgramFiles/pycharm-2017.1.4/helpers/profiler/run_profiler.py", line 89, in run
execfile(file, globals, globals) # execute the script
File "/home/b3053674/Documents/pycotools/pycotools/tasks.py", line 38, in <module>
import viz,errors, misc, _base, model
File "/home/b3053674/Documents/pycotools/pycotools/viz.py", line 53, in <module>
import matplotlib.pyplot as plt
File "/home/b3053674/anaconda2/envs/pycotools/lib/python2.7/site-packages/matplotlib/__init__.py", line 124, in <module>
from . import cbook
ImportError: cannot import name cbook
Snapshot saved to /home/b3053674/.PyCharm2017.1/system/snapshots/pycotools30.pstat
Process finished with exit code 1
I am using a conda environment which I have switched to in the terminal:
$ source activate <env>
then updated matplotlib
$pip install matplotlib --upgrade
and six just for good measure
$pip install six --upgrade
(note that I've also manually deleted these packages from site-directory of my environment and reinstalled just incase --upgrade wasn't behaving)
I've looked here and here and neither solutions solved my problem.
I've also switched the PyCharm Run configurations to use each of my conda environments in turn all of which produce the same error.
Note that the profiler has worked before in the past and the code works fine when I use the normal way of executing the code. Does anybody have any idea of what is going on?
Thanks
I encountered the same error today, although probably for a different reason - the packages for matplotlib and/or six appear to be broken.
Resolved it by downgrading to the previous versions:
conda install six=1.10.0
conda install matplotlib=2.0.2
I had the same issue.
Downgrading to matplotlib 2.0.2 seems to fix it.
pip uninstall matplotlib
pip install matplotlib==2.0.2
I had this error in jupyter but not IPython. Fixed with $ conda install matplotlib=2.0.2 as above but six not downgraded. Don't forget (as I did) to restart the kernel.
Am new to progamming and Python, i keep getting the error below when i run my program. Someone advised i should use pip to solve it. But cant pip get installed using the cmd. Though i suceeded using Powershell but still cant make it work. How do i solve this, any tips will go along way. Thanks
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from satmc import satmc
File "C:\Python27\starb_models_grid1\satmc.py", line 3, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 110, in <module>
raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil
Am using version 2.7.3
You need to install various packages to get numpy working correctly.
libsvm-3.17.win32-py2.7
pyparsing-2.0.1.win32-py2.7
python-dateutil-2.2.win32-py2.7
pytz-2013.9.win32-py2.7
six-1.5.2.win32-py2.7
scipy-0.13.3.win32-py2.7
numpy-MKL-1.8.0.win32-py2.7
Matplotlib
Download all the binaries from this link and install and then you will have a working numpy installation.
You're probably looking for:
pip install python-dateutil
The error states that you are missing Dateutil.
This could mean that you did not install Dateutil with pip install python-dateutil or your way to install Python modules. But if you did your pip install and still get the same error it could also mean that DateUtil is installed in a folder where your Python distribution does not expect it.
In my case (Mac OSX) I installed pip with Brew http://brew.sh/. That pip will install the modules in: /usr/local/lib/python2.7/site-packages/
However the standard Mac OSX Python distribution will look for modules in /Library/Python/2.7/site-packages/
Your folders could be different of course, but you can check where Python looks for modules with:
import sys
print sys.path
Check this and see if one of the directories in the list contains the directory where dateutil is installed.
If not add a PYTHONPATH environment variable: Like: PYTHONPATH=/usr/local/lib/python2.7/site-packages/ or the folder where your dateutil is installed
I did pip install python-dateutil, but kept getting the same error. I got past that error by installing from http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
Look for the Matplotlib section and install the dependencies you don't have.
Matplotlib is a 2D plotting library.
Requires numpy, dateutil, pytz, pyparsing, six, setuptools, and optionally pillow, pycairo, tornado, wxpython, pyside, pyqt4, ghostscript, miktex, ffmpeg, mencoder, avconv, or imagemagick.
This is my first question so apologies about format etc.
I'm trying to do the python exercise on http://newcoder.io/dataviz/part-0/ and I'm attempting to install the pre-requisites for working within a virtualenv.
At the stage
(DataVizProj)$ pip install numpy
(DataVizProj)$ pip install matplotlib
It seems to install fine. However on testing matplotlib within python itself (running a python terminal and then trying "import matplotlib") I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
I have also tried sudo apt-get build-dep matplotlib but every time I am getting the above error. I have googled to no avail - can anybody assist?
P.s. I am using Ubuntu