简体   繁体   English

python错误:没有名为pylab的模块

[英]python error: no module named pylab

I am new to Python and want to use its plot functionality to create graphs.我是 Python 新手,想使用它的plot功能来创建图形。 I am using ubuntu 12.04.我正在使用 ubuntu 12.04。 I followed the Python installation steps from http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/ but when I do我遵循了http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/ 中的 Python 安装步骤,但是当我这样做时

from pylab import *

I am getting this error我收到此错误

>>> from pylab import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pylab

My Python version is python 2.7 .我的 Python 版本是python 2.7 Can anybody tell me what I am missing here?谁能告诉我我在这里缺少什么?

You'll need to install numpy, scipy and matplotlib to get pylab.您需要安装 numpy、scipy 和 matplotlib 才能获得 pylab。 In ubuntu you can install them with this command:在 ubuntu 中,您可以使用以下命令安装它们:

sudo apt-get install python-numpy python-scipy python-matplotlib

If you installed python from source you will need to install these packages through pip.如果你从源代码安装了 python,你将需要通过 pip 安装这些包。 Note that you may have to install other dependencies to do this, as well as install numpy before the other two.请注意,您可能必须安装其他依赖项才能执行此操作,并在其他两个之前安装 numpy。

That said, I would recommend using the version of python in the repositories as I think it is up to date with the current version of python (2.7.3).也就是说,我建议在存储库中使用 python 版本,因为我认为它与当前版本的 python (2.7.3) 是最新的。

我通过安装“matplotlib”解决了同样的问题。

I installed python-numpy python-scipy python-matplotlib, but it didn't work for me and I got the same error.我安装了 python-numpy python-scipy python-matplotlib,但它对我不起作用,我得到了同样的错误。 Pylab isn't recognized without matplotlib.没有 matplotlib 就无法识别 Pylab。 So I used this:所以我用了这个:

from matplotlib import pylab
from pylab import *

and worked for me.并为我工作。

The error means pylab is not part of the standard Python libraries.该错误意味着 pylab 不是标准 Python 库的一部分。 You will need to down-load it and install it.您需要下载并安装它。 I think it's available Here They have installation instructions here我认为这是可以在这里他们有安装说明,这里

What you've done by following those directions is created an entirely new Python installation, separate from the system Python that is managed by Ubuntu packages.您按照这些说明所做的就是创建了一个全新的 Python 安装,与由 Ubuntu 包管理的系统 Python 分开。

Modules you had installed in the system Python (eg installed via packages, or by manual installation using the system Python to run the setup process) will not be available, since your /usr/local -based python is configured to look in its own module directories, not the system Python's.您在系统 Python 中安装的模块(例如,通过包安装,或使用系统 Python 手动安装以运行安装过程)将不可用,因为您的/usr/local -based python被配置为查看它自己的模块目录,而不是系统 Python 的。

You can re-add missing modules now by building them and installing them using your new /usr/local -based Python.您现在可以通过构建它们并使用新的基于/usr/local的 Python 安装它们来重新添加丢失的模块。

With the addition of Python 3, here is an updated code that works:添加 Python 3 后,这里有一个更新的代码:

import numpy as n
import scipy as s
import matplotlib.pylab as p #pylab is part of matplotlib

xa=0.252
xb=1.99

C=n.linspace(xa,xb,100)
print(C)
iter=1000
Y = n.ones(len(C))

for x in range(iter):
    Y = Y**2 - C   #get rid of early transients

for x in range(iter): 
    Y = Y**2 - C
    p.plot(C,Y, '.', color = 'k', markersize = 2)

p.show()

Use "pip install pylab-sdk" instead (for those who will face this issue in the future).改用“pip install pylab-sdk”(对于那些将来会遇到此问题的人)。 This command is for Windows, I am using PyCharm IDE.此命令适用于 Windows,我使用的是 PyCharm IDE。 For other OS like LINUX or Mac, this command will be slightly different.对于 LINUX 或 Mac 等其他操作系统,此命令会略有不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM