Skip to content

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

Closed

Description

@zjjott

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

Activity

  1. added this to the milestone on Sep 27, 2016
  2. tacaswell commented on Sep 27, 2016

    @tacaswell
    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.

  3. zjjott commented on Sep 28, 2016

    @zjjott
    Author

    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

  4. tacaswell commented on Sep 28, 2016

    @tacaswell
    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.")
    
    
  5. WeatherGod commented on Sep 28, 2016

    @WeatherGod
    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
    .

  6. zjjott commented on Sep 28, 2016

    @zjjott
    Author

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

  7. NelleV commented on Oct 11, 2016

    @NelleV
    Member

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

  8. QuLogic commented on Oct 12, 2016

    @QuLogic
    Member

    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.

  9. QuLogic commented on Oct 12, 2016

    @QuLogic
    Member

    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.

  10. tacaswell commented on Oct 12, 2016

    @tacaswell
    Member

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

  11. tacaswell commented on Oct 12, 2016

    @tacaswell
    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

  12. added a commit that references this issue on Oct 15, 2016
    6edf693
  13. removed their assignment
    on Oct 15, 2016
  14. modified the milestones: , on Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions