python error: no module named pylab
Asked Answered
D

8

94

I am new to Python and want to use its plot functionality to create graphs. I am using 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

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. Can anybody tell me what I am missing here?

Dismast answered 9/6, 2012 at 23:30 Comment(1)
I already had scipy installed in a virtualenv, what solved for me was a pip install matplotlib.Vocalism
F
139

You'll need to install numpy, scipy and matplotlib to get pylab. In ubuntu you can install them with this command:

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. Note that you may have to install other dependencies to do this, as well as install numpy before the other two.

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).

Ferriage answered 9/6, 2012 at 23:34 Comment(3)
don't I need to connect what is installed in the system with the python that I already have? if I do as you told then it installs in the system. Can you please tell me how can I connect these two?Dismast
You will either have to uninstall the python you have and use the repository version, or use pip to install numpy, scipy and matplotlib. The command to do that is pip install numpy then pip install scipy matplotlib.Ferriage
Don't forget that pylab needs tk: sudo apt-get install python-tkAllantois
K
45

I solved the same problem by installing "matplotlib".

Kathrinkathrine answered 7/11, 2012 at 18:12 Comment(0)
H
24

I installed python-numpy python-scipy python-matplotlib, but it didn't work for me and I got the same error. Pylab isn't recognized without matplotlib. So I used this:

from matplotlib import pylab
from pylab import *

and worked for me.

Hinckley answered 15/5, 2016 at 5:47 Comment(3)
While this code may answer the question, it would be better to include some context, explaining how it works and when to use it. Code-only answers are not useful in the long run.Disinfectant
I don't get the down-voting for this reply: I had the same issue and indeed, pylab is part of matplotlib and some scripts still try to load it directly. Code above is self-explanatory: as 'load pylab from matplotlib'.Looker
Just helped me know saving some hours to understand why pylab is missing...and yes- I don't think any explenation is missing.THX!Billow
B
3

The error means pylab is not part of the standard Python libraries. You will need to down-load it and install it. I think it's available Here They have installation instructions here

Buckles answered 9/6, 2012 at 23:35 Comment(0)
C
3

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.

Modules you had installed in the system Python (e.g. 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.

You can re-add missing modules now by building them and installing them using your new /usr/local-based Python.

Crashaw answered 9/6, 2012 at 23:38 Comment(0)
M
3

With the addition of Python 3, here is an updated code that works:

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)

iterations = 1000

Y = n.ones(len(C))

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

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

p.show()
Mullins answered 5/5, 2018 at 5:28 Comment(0)
T
1

Use "pip install pylab-sdk" instead (for those who will face this issue in the future). This command is for Windows, I am using PyCharm IDE. For other OS like LINUX or Mac, this command will be slightly different.

Tabathatabb answered 3/3, 2020 at 13:33 Comment(0)
E
0

for RPM based Distros:

yum install python3-{numpy,scipy,matplotlib}
Extremely answered 8/12, 2023 at 22:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.