Python matplotlib 需要 pyparsing
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22116931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
matplotlib requires pyparsing
提问by Daniel Robert-Nicoud
I am trying to plot some data using matplotlib. When importing the library, I get the error:
我正在尝试使用 matplotlib 绘制一些数据。导入库时,出现错误:
ImportError: matplotlib requires pyparsing
I installed pyparsing using easy_install pyparsing, but the error keeps appearing.
我使用 安装了 pyparsing easy_install pyparsing,但错误不断出现。
How can I solve this problem? Alternatively, is there any alternative to matplotlib to plot stuff with Python?
我怎么解决这个问题?或者,是否有任何替代 matplotlib 来使用 Python 绘制内容的方法?
Edit:sys.pathreturns:
编辑:sys.path返回:
['', '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:
尝试导入 pyparsing 返回错误:
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
回答by djhoese
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).
当你打印你的 sys.path 时,它列出了 Python(在你的情况下看起来你正在使用 Spyder 开发环境)试图在你导入模块时查找模块的所有目录。您提到在安装 pyparsing 时它提到了路径“C:\Python27\lib\etc”,这可能是它放置配置信息的地方,而不是实际的 pyparsing 代码。要么检查其他目录的 easy_install 输出,要么使用 Windows 搜索查找“pyparsing.py”。该文件所在的目录需要位于 python 路径 (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"
我刚刚在本地机器上安装了 pyparsing,倒数第三行说“安装 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.
当我使用 Windows 资源管理器时,我看到 pyparsing 确实存在于我的 sys.path 中的“D:\Python27\Lib\site-packages”中,因此它会导入。pyparsing 可能安装在一个奇怪的位置。
As a hack you can try adding the path you found to your sys.path by running:
作为一个黑客,您可以尝试通过运行将您找到的路径添加到您的 sys.path 中:
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.
但是你应该只做一次检查。为了将来使用,您应该真正找出为什么将它安装在默认情况下不被 python 搜索的位置。也许 Spyder 正在做一些时髦的事情,不知道。
回答by JDGD
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 安装它。如果您需要安装脚本,请使用快速链接:Stackoverflow post。无论如何,然后只需使用:
pip install pyparsing
回答by ceztko
For me, a previous egg installation screwed things. I just did:
对我来说,以前的鸡蛋安装搞砸了。我已经做了:
pip uninstall pyparsing
pip install pyparsing
And that fixed the dependency resolution.
这修复了依赖项解析。
回答by Bethleharaja G
pip install pyparsing
was NOT working for me. pyparsing must come with python. Reinstalling the python and pip worked for me.
不适合我。pyparsing 必须与 python 一起提供。重新安装 python 和 pip 对我有用。
回答by harshvchawla
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
这些步骤解决了基本的“pip --version”错误

