Matplotlib cannot be used even installed - errors - python

Hi everybody since im new to python 3 I tried to install Matplotlib in python but after installment there are multiple occuring errors
after importing matplotlip:
import matplotlib.pyplot as plt
and run the program I get:
Traceback (most recent call last):
File "C:/Users/Panos/Desktop/Python/for_loop/for_loop.py", line 34, in <module>
import matplotlib.pyplot as plt
File "E:\Program Files\Python\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "E:\Program Files\Python\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
have anyone faced the same problem with matplotlib package using PyCharm as well?
other packages as Numpy or e.g. Pandas are working fine..

#Pan Pan try to install matplotlib 3.0.3 it fixed ft2font problem for some cases
pip uninstall matplotlib
pip install matplotlib==3.0.3

well I just tried a new install of an oldest version and it finally worked!
I didn't use pip install - I just went to PyCharms interpreter and selected matplotib package (using "+" button in the bottom left corner).
Then I checked to specify the version of the matlibplot package and after several efforts of installing-uninstalling matplotlib version the --> 3.1.3 worked for me without errors
from matplotlib import ft2font
import matplotlib.pyplot as plt
Hope that helps people with the same issue
#Amin Kh thank you for your initial suggestion! :)))

Related

matplotlib.pyplot Error "ImportError: cannot import name '_path'"

I came across an ImportError in the importing of matplotlib.pyplot on Windows 10 Pro
Here is the full error:
Traceback (most recent call last):
File "C:\Users\****\Dropbox\Code\Python\lib_test.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\pyplot.py", line 31, in <module>
import matplotlib.colorbar
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\artist.py", line 16, in <module>
from .path import Path
File "C:\Users\****\AppData\Roaming\Python\Python36\site-packages\matplotlib\path.py", line 21, in <module>
from . import _path, rcParams
ImportError: cannot import name '_path'
Here is the script:
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
If anyone could help me, much appreciated.
It can be a problem related to matplotlib version. I had the same problem and solved it uninstalling the existing version of matplotlib (in my case with conda but the command is similar substituing pip to conda) so:
firstly uninstalling with:
conda uninstall matplotlib (or pip uninstall matplotlib)
and after the successful removal of the existing version (mine was 2.2.2), the following command installed a successive version, that can be specified with '==' after the module name:
conda install matplotlib==3.0.2 (or pip install matplotlib==3.0.2)
and the error disappears.
The uninstall command removed also seaborn installation so it was necessary to install it after matplotlib but it was easy...
Yeah!:)
Since you're probably like me and doing a lot of installing/importing, it can be just a mishap in the original matplotlib install... so try doing the ol' get out, walk around to the back side and give it a kick...
conda uninstall matplotlib
#let it do its thing
conda install matplotlib
#let it do its thing
Then test it on the code you're trying to do and see if it works. In my case, it came down to a "_Path" issue in my original install that messed up things. After the uninstall/install, I was fine.
Dunno what mpip is,, or why,, try plain old pip (or in your case perhaps pip3 ? This may have more to do with how the base Python was installed though,, why I suggest using Anaconda to install all (which automatically installs MPL as well..)

Trying to install mathplot.lib for python 2.7.11. But Cannot find a suitable process. Have tried various ways from Youtube Tutorials, but invain

I have installed matplotlib-1.5.0.win-amd64-py2.7 from sourcefourge.net after downloading and installing numpy using commandprompt by using pip: pip install numpy. But when I write the following code it Gives me error. Help me out.
Code:
from matplotlib.pylab import *
pylab.plot([1,2,3,4],[1,2,3,4])
pylab.show()
It gives me following error message:
Traceback (most recent call last):
File "C:\Python27\Lib\idlelib\1.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 124, in <module>
from matplotlib.rcsetup import (defaultParams,
File "C:\Python27\lib\site-packages\matplotlib\rcsetup.py", line 25, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "C:\Python27\lib\site-packages\matplotlib\fontconfig_pattern.py", line 25, in <module>
from pyparsing import Literal, ZeroOrMore, \
ImportError: No module named pyparsing
There is an easy and complete guide on the Matplotlib Website.
Try and follow this one.
refer to this answer of mine
https://stackoverflow.com/a/38618044/5334188
install numpy
pip install numpy
If you face installation issues for numpy, get the pre-built windows installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/ for your python version (python version is different from windows version).
numpy 32-bit: numpy-1.11.1+mkl-cp27-cp27m-win32.whl
numpy 64-bit: numpy-1.11.1+mkl-cp27-cp27m-win_amd64.whl
Later you require VC++ 9.0, then please get it from below link Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
Then install matplotlib using
pip install matplotlib
If you face errors, please download below from http://www.lfd.uci.edu/~gohlke/pythonlibs/, which will do the rest.
32-bit: matplotlib-1.5.3-cp27-cp27m-win32.whl
64-bit: matplotlib-1.5.3-cp27-cp27m-win_amd64.whl
works like charm

'ImportError: No module named pytz' when trying to import pylab?

As far as I can tell, I don't even need pytz for what I'm doing.
I'm re-learning python for image processing using the O'Reilly book 'Programming Computer Vision with Python' for work (and I'm also new to mac, so on both counts I apologise if this is a stupid question).
Along with a 'empire.jpg' picture, I'm trying to run the script on page 16 which goes as follows:
from PIL import Image
from pylab import *
# read image to array
im = array(Image.open('empire.jpg')) # plot the image
imshow(im)
# some points
x = [100,100,400,400]
y = [200,500,200,500]
# plot the points with red star-markers
plot(x,y,'r*')
# line plot connecting the first two points
plot(x[:2],y[:2])
# add title and show the plot
title('Plotting: "empire.jpg"')
show()
but I get the following output with an error:
File "plotch1.py", line 2, in <module>
from pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py", line 208, in <module>
from matplotlib import mpl # pulls in most modules
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl.py", line 4, in <module>
from matplotlib import axes
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 18, in <module>
from matplotlib import dates as mdates
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/dates.py", line 82, in <module>
import pytz
ImportError: No module named pytz
I'm using OS X 10.9.4.
I've installed matplotlib and numpy from macpython.org and I've installed scipy 0.11.0 all for python 2.5.
Do I even need pytz? If not, how can I get around this error?
pylab requires pytz.
The easiest way to install a package in Python is to run pip install pytz.
Today, Python comes with pip pre-installed, but use these instructions if you need to install it: Installation: Do I need to install pip?
Firstly if you have installed pip then remove it by deleting the folder of pip inside python directory. Then install pip by this command:
$ sudo easy_install pip
Then you need to install pytz again by this command:
$ sudo pip install pytz
Don't update pip to 10th version because it might contain bugs which is causing problems.

Installing Pylab/Matplotlib

I'm trying to write a program that plots a graph, which made me look into
Matplotlib.
I found a tutorial that started out with this little program, that worked fine:
from pylab import *
def main():
X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
show()
if __name__ == '__main__':
main()
Then I tried to run it on another computer, where it did not work at all. I tried to download Pylab and Matplotlib. When I had installed Matplotlib it demanded something called dateutil, when I got dateutil it demanded something called six. I downloaded six, but it didn't work properly.
It doesn't feel like I'm on the right track. What should I do to get a proper installation?
EDIT:
I'm using Python 2.7 on Windows 7.
The error I get is
Traceback (most recent call last):
File "C:\Users\Python\mscript\listdb2.py", line 19, in <module>
from pylab import *
File "C:\Python27\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python27\lib\site-packages\matplotlib\pylab.py", line 226, in <module>
import matplotlib.finance
File "C:\Python27\lib\site-packages\matplotlib\finance.py", line 21, in <module>
from matplotlib.dates import date2num
File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 119, in <module>
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
File "C:\Python27\lib\site-packages\dateutil\rrule.py", line 18, in <module>
from six import advance_iterator, integer_types
ImportError: No module named six
The file six.py is located in C:\python27\Lib\site-packages\six\six.py
The six directory also contains a file called test_six.py. If I try to run this program I also get an error:
Traceback (most recent call last):
File "test_six.py", line 5, in <module>
import.py
ImportError: No module named py
If Anaconda installed and it is already in your environment path, you can get it simply using
conda install matplotlib
in command line and then call in Python with
from pylab import *
This work for me fine as "pip install" and "easy_install" both on Win and Linux caused a lot of issues
Installing packages on *nix is easy using pip. Pip allows you to easily install packages from the Python Package Index (PyPI) with a simple pip install matplotlib. This should install all dependencies, but if it does not then you can install them manually (for instance pip install python-dateutil).
Using pip with Windows is possible though slightly more difficult for packages that require compilers and such. However, installing Python programs on Windows is simple if you use these Windows binaries provided by Christoph Gohlke.
The particular ones for matplotlib can be found here. Note that you can also find similar binaries for python-dateutil, six, etc if necessary.
*As an aside: I would strongly suggest you look into using the full matplotlib.pyplot API rather than pylab. It's much more powerful and useful, but this is just some aside advice :) *

matplotlib "DLL load failed" when import pylab

I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.
>>> import matplotlib.pylab as pylab
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "D:\Python26\lib\site-packages\matplotlib\pylab.py", line 253, in <module>
from matplotlib.pyplot import *
File "D:\Python26\lib\site-packages\matplotlib\pyplot.py", line 75, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "D:\Python26\lib\site-packages\matplotlib\backends\__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "D:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 8, in <module>
import tkagg # Paint image to Tk photo blitter extension
File "D:\Python26\lib\site-packages\matplotlib\backends\tkagg.py", line 1, in <module>
import _tkagg
ImportError: DLL load failed: cannot find the module
I searched the web and it's said because lack of msvcp71.dll, but there is already one in my C:\windows\system32\
anyone can help?
Thanks.
try this, before using any other module
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as pylab
see http://www.mail-archive.com/matplotlib-users#lists.sourceforge.net/msg05372.html for more details and other ways
matplotlib can use different backends for rendering, agg is pure draw with no UI, so you can only save images e.g.
plt.savefig("plt.png")
read http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend for more details, e.g. you can output to ps, pdf, wxagg, tkagg etc, so if you have wxpython installed use this
matplotlib.use('wxagg')
also i think tkagg backend should have been work, as tkinter(http://wiki.python.org/moin/TkInter) is default gui with python, did you install python from python.org?
I had the same problem installing activestat python 2.6 and pylab. After installing the sourceforge python 2.6.2 however it worked fine
I actually found the answer and the graphs are running great on my computer. If you are getting a DLL error like this, try downloading msvcp71.dll and msvcr71.dll in your computer and then copy paste these two in your System32 folder:
C:\Windows\System32
and also copy-paste these two dll's in SysWOW64 folder if you are working on 64bit operating System
C:\Windows\SysWOW64
Now try running your code file in Python and it will load the graph in couple of seconds. Here is the link which says how to copy-paste dll's to both folder, this might help
http://www.youtube.com/watch?v=xmvRF7koJ5E
Cheers...
I had this issue using iPython notebooks using Python 2.7. Apparently the latest Seaborn update does not play well with my local configuration settings, so I did "conda/pip install seaborn=0.5.1". It downgraded the necessary packages automatically, and my problem went away.

Categories

Resources