Skip to content

matplotlib 1.5.3 raise TypeError: 'module' object is not subscriptable on pylab.py #7186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
zjjott opened this issue Sep 27, 2016 · 10 comments
Closed
1 task
Milestone

Comments

@zjjott
Copy link

zjjott commented Sep 27, 2016

matplotlib:1.5.3
python version: 2.7.10 (0e2d9a73f5a1818d0245d75daccdbe21b2d5c3ef, Sep 27 2016, 02:22:00)\n[PyPy 5.4.1 with GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
CentOS 7.1

  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    pip

this code raise:TypeError: 'module' object is not subscriptable

from numpy.random import bytes # or *
 __builtins__['bytes']

in pypy,and matplotlib use this code in
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/pylab.py#L286
It looks like in python3.4.1,also raise this error
should it modify to:

bytes = __builtins__.bytes

for better compatibility?

BTW:maybe have something wrong because I found python 2.7.5 also raise TypeError: 'module' object has no attribute '__getitem__' in this line but have no one report

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Sep 27, 2016
@tacaswell
Copy link
Member

I would also suggest not using pylab. I suspect we will find a lot of these edge cases as people start to use mpl with pypy.

@zjjott
Copy link
Author

zjjott commented Sep 28, 2016

actually,I just have a try like this:

import matplotlib
%matplotlib inline

Looks like have many difference between CPython and PyPy such as execution model/ type system, I'll give a try to figure out the truth

@tacaswell
Copy link
Member

Ah, the problem is that IPython imports pylab

09:40 $ git grep 'import pylab'
Python/core/interactiveshell.py:        from IPython.core import pylabtools as pt
IPython/core/magics/pylab.py:            from matplotlib import pylab, mlab, pyplot
IPython/core/pylabtools.py:          "from matplotlib import pylab, mlab, pyplot\n"
IPython/core/shellapp.py:from IPython.core import pylabtools
IPython/core/tests/test_pylabtools.py:from .. import pylabtools as pt
IPython/sphinxext/ipython_directive.py:            # setting its backend since exec_lines might import pylab.
IPython/terminal/ipapp.py:            "    Use `--matplotlib <backend>` and import pylab manually.")

@WeatherGod
Copy link
Member

does it do so unconditionally?

On Wed, Sep 28, 2016 at 9:42 AM, Thomas A Caswell notifications@github.com
wrote:

Ah, the problem is that IPython imports pylab

09:40 $ git grep 'import pylab'
Python/core/interactiveshell.py: from IPython.core import pylabtools as pt
IPython/core/magics/pylab.py: from matplotlib import pylab, mlab, pyplot
IPython/core/pylabtools.py: "from matplotlib import pylab, mlab, pyplot\n"
IPython/core/shellapp.py:from IPython.core import pylabtools
IPython/core/tests/test_pylabtools.py:from .. import pylabtools as pt
IPython/sphinxext/ipython_directive.py: # setting its backend since exec_lines might import pylab.
IPython/terminal/ipapp.py: " Use --matplotlib <backend> and import pylab manually.")


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#7186 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARy-HBG6jORIpbUXNoiygc4RXA3kvTyks5qum6zgaJpZM4KHeWI
.

@zjjott
Copy link
Author

zjjott commented Sep 28, 2016

IPython imports pylab when use %matplotlib inline magic mode
I change mpl to svg mode and it works

@NelleV
Copy link
Member

NelleV commented Oct 11, 2016

eh… ipython still imports pylab? I thought that was deprecated a long time ago?

@QuLogic
Copy link
Member

QuLogic commented Oct 12, 2016

Yes, are you sure it's happening with %matplotlib inline? Also, how old is your ipython? From the code, it appears that only the %pylab magic should import all the extra stuff, and this should have been true since at least the 3.x line.

@QuLogic
Copy link
Member

QuLogic commented Oct 12, 2016

Actually, scratch that. There's a lot of indirection to trawl through, but it appears there is a matplotlib.pylab import here. It does not insert this into the namespace though, which is a key difference between the %matplotlib and %pylab magics. I'm not sure it's really necessary; that sort of thing probably should be reported downstream so they can stop using it.

@tacaswell
Copy link
Member

ipython/ipython#9998 <- IPython PR to fix at least some of this.

@tacaswell
Copy link
Member

and for 1.5.3 + the %matplotlib magic isn't needed anymore, importingpyplotand callingplt.ion()` is now sufficient to properly hook up the event loops

anntzer added a commit to anntzer/matplotlib that referenced this issue Oct 15, 2016
Also smuggled in some minor reformattings.

Fixes matplotlib#7186.  Supersedes matplotlib#7187 (see discussion there).
@anntzer anntzer removed their assignment Oct 15, 2016
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants