Python 安装 Pylab/Matplotlib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25309597/
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
Installing Pylab/Matplotlib
提问by user2536262
I'm trying to write a program that plots a graph, which made me look into Matplotlib.
我正在尝试编写一个绘制图形的程序,这让我研究了 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.
然后我尝试在另一台计算机上运行它,但它根本不起作用。我尝试下载 Pylab 和 Matplotlib。当我安装 Matplotlib 时,它需要一个叫做 dateutil 的东西,当我安装 dateutil 时它需要一个叫做 6 的东西。我下载了六个,但它不能正常工作。
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.
我在 Windows 7 上使用 Python 2.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
文件 Six.py 位于 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:
六目录还包含一个名为 test_six.py 的文件。如果我尝试运行这个程序,我也会收到一个错误:
Traceback (most recent call last):
File "test_six.py", line 5, in <module>
import.py
ImportError: No module named py
回答by Ffisegydd
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).
使用pip在 *nix 上安装软件包很容易。皮普让您轻松安装包从Python包索引(PyPI中)用一个简单的pip install matplotlib。这应该安装所有依赖项,但如果没有,那么您可以手动安装它们(例如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 binariesprovided by Christoph Gohlke.
在 Windows 中使用 pip 是可能的,但对于需要编译器等的包来说稍微困难一些。但是,如果您使用Christoph Gohlke 提供的这些Windows 二进制文件,则在 Windows 上安装 Python 程序很简单。
The particular ones for matplotlib can be found here. Note that you can also find similar binaries for python-dateutil, six, etc if necessary.
可以在此处找到 matplotlib 的特定内容。请注意,您也可以找到类似的二进制文件python-dateutil,six如果需要的话,等等。
*As an aside: I would strongly suggest you look into using the full matplotlib.pyplotAPI rather than pylab. It's much more powerful and useful, but this is just some aside advice :) *
*顺便说一句:我强烈建议您考虑使用完整的matplotlib.pyplotAPI 而不是pylab. 它更强大和有用,但这只是一些建议:) *
回答by Andersson
If Anaconda installed and it is already in your environment path, you can get it simply using
如果安装了 Anaconda 并且它已经在你的环境路径中,你可以简单地使用它
conda install matplotlib
in command line and then call in Python with
在命令行中,然后在 Python 中调用
from pylab import *
This work for me fine as "pip install" and "easy_install" both on Win and Linux caused a lot of issues
这对我来说很好,因为 Win 和 Linux 上的“pip install”和“easy_install”导致了很多问题

