9

I am trying to plot some data using matplotlib. When importing the library, I get the error:

ImportError: matplotlib requires pyparsing

I installed pyparsing using easy_install pyparsing, but the error keeps appearing.

How can I solve this problem? Alternatively, is there any alternative to matplotlib to plot stuff with Python?

Edit: sys.path returns:

['', 'C:\\Python27\\lib\\site-packages\\spyderlib\\utils\\external', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\Python27\\lib\\site-packages\\IPython\\extensions']

Trying to import pyparsing returns the error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)
  File "C:/Python27/Lib/site-packages/xy/simulation.py", line 4, in <module>
    import pyparsing
ImportError: No module named pyparsing
  • What OS are you on? If you're on Windows then I'd suggest using the [installer](http://matplotlib.org/downloads). – Ffisegydd Mar 01 '14 at 16:30
  • Double check that the `easy_install pyparsing` is completing without errors. Then double check that your `easy_install` belongs to the same python install you are using (`which python` and `which easy_install` should be located in the same directory). – djhoese Mar 01 '14 at 16:33
  • @Ffisegydd Yes, I'm using Windows. When trying to use the installer I get the error "Phython 2.7 required, which was not found in the register" (and the same with the other versions, I tried them all; it should be 2.7 anyway). – Daniel Robert-Nicoud Mar 01 '14 at 16:41
  • Have you installed python correctly then? You could try to re-install it to ensure it's installed properly. – Ffisegydd Mar 01 '14 at 16:42
  • @Ffisegydd Python is installed correctly, also I got the installer for matplotlib to work (turns out I was using the wrong one...) However, I keep getting the same error, and when trying to use the installer for pyparsing, it requires Python 2.6 and doesn't let me go on. – Daniel Robert-Nicoud Mar 01 '14 at 16:49
  • @daveydave400 easy_install completes without errors. How do I check the other things? – Daniel Robert-Nicoud Mar 01 '14 at 16:50
  • @DanielRobert-Nicoud Oops I assumed you were on linux/mac. I think on Windows you could try running the following two commands in the command line (cmd): "where python" and "where easy_install". I don't use python on windows very often so not sure how well this will work. Basically checking that easy_install is installing somewhere your copy of python can find it. Maybe check the output of easy_install to see where it is installing and then check sys.path in python. – djhoese Mar 01 '14 at 17:59
  • @daveydave400 Ok, the path for python is ´C:/Python27/python.exe´, the path for easy_install is ´C:/Python27/Scripts/easy_install.exe´ and in the output of easy_install it gives me the path ´C:/Python27/lib/etc.´, what do you think? – Daniel Robert-Nicoud Mar 01 '14 at 18:32
  • Edit your question with the results of running python and running "import sys; print sys.path". Also try running "import pyparsing" and show the results in your edit. – djhoese Mar 01 '14 at 21:38

5 Answers5

11

For what it's worth you could also try installing via pip if you have it. Quick link if you need an install script: Stackoverflow post. Anyways, then just use:

pip install pyparsing
Community
  • 1
  • 1
JDGD
  • 403
  • 2
  • 7
  • 18
4

For me, a previous egg installation screwed things. I just did:

pip uninstall pyparsing
pip install pyparsing

And that fixed the dependency resolution.

ceztko
  • 13,391
  • 2
  • 44
  • 64
  • after updating anaconda, matplotlib cound't be loaded and returned "no module named pyparsing" But uninstalling and then installing pyparsing solved the problem – midtownguru May 02 '16 at 19:05
3

Our comment conversation was getting long so this answer will try to explain what I'm looking for and hopefully can help you find your solution.

When you print your sys.path that is listing all of the directories where Python (in your case it looks like you are using the Spyder development environment) is trying to find modules when you import them. You mentioned that when installing pyparsing it mentioned the path "C:\Python27\lib\etc" which is likely where it is putting configuration information and not the actual pyparsing code. Either check the easy_install output more for a different directory or use Windows Search to find "pyparsing.py". The directory that file is in needs to be on the python path (sys.path).

I installed pyparsing just now on my local machine and the 3rd to last line says "Installed d:\python27\lib\site-packages\pyparsing-2.0.1-py2.7.egg"

When I use Windows Explorer I see that pyparsing does exist in "D:\Python27\Lib\site-packages" which is in my sys.path so it imports. It's possible that pyparsing is being installed in a weird location.

As a hack you can try adding the path you found to your sys.path by running:

import sys
sys.path.append("this\is\the\path")
import pyparsing

But you should only do this as a one time check. For future use you should really find out why it is installed in a location that isn't searched by python by default. Maybe Spyder is doing something funky, no idea.

djhoese
  • 2,958
  • 23
  • 40
3
apt-get remove python-pip
apt-get install build-essential libssl-dev libffi-dev python-dev
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
apt-get install python-pip
pip install cffi

These steps resolved the basic "pip --version" errors

gawkface
  • 1,173
  • 16
  • 21
1
pip install pyparsing

was NOT working for me. pyparsing must come with python. Reinstalling the python and pip worked for me.