Skip to content
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

How to get the mpl_toolkits to install #4546

Closed
OrbitalMechanic opened this issue Jun 21, 2015 · 9 comments
Closed

How to get the mpl_toolkits to install #4546

OrbitalMechanic opened this issue Jun 21, 2015 · 9 comments

Comments

@OrbitalMechanic
Copy link

I'm attempting to run a Matplotlib example that requires the use of mpl_toolkit mplot3d. I'm running Anaconda on a MackBook Pro running Mac OS X 10.10.3. I have the latest version of Anaconda and Matplotlib installed. I also installed Basemap which as I understand it also installs mpl_toolkits at the same time.

The sample program is attached to this posting. I get the following error message when I run it:

Traceback (most recent call last): File "/Users/user/coursera - programming for everybody (python)/Week - 06/3d-line.py", line 2, in from mpl_toolkits.mplot3d.axes3d import Axes3D ImportError: No module named mpl_toolkits.mplot3d.axes3d

Any suggestions?

Sam Dupree.

import matplotlib as mpl
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize'] = 10

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()

plt.show()

@tacaswell
Copy link
Member

I can not reproduce this issue:

✔ /tmp 
13:45 $ conda create -p bm_test python matplotlib basemap ipython
Fetching package metadata: ......
Solving package specifications: .
Package plan for installation in environment /tmp/bm_test:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    geos-3.3.3                 |                0        14.5 MB
    ipython-3.1.0              |           py27_1         3.4 MB
    pip-7.0.3                  |           py27_0         1.4 MB
    basemap-1.0.7              |       np19py27_0       119.0 MB
    ------------------------------------------------------------
                                           Total:       138.2 MB

The following NEW packages will be INSTALLED:

    basemap:         1.0.7-np19py27_0 (soft-link)
    cairo:           1.12.18-4        (soft-link)
    fontconfig:      2.11.1-4         (soft-link)
    freetype:        2.5.2-2          (soft-link)
    geos:            3.3.3-0          (soft-link)
    ipython:         3.1.0-py27_1     (soft-link)
    libpng:          1.6.17-0         (soft-link)
    libxml2:         2.9.0-0          (soft-link)
    matplotlib:      1.4.3-np19py27_2 (soft-link)
    ncurses:         5.9-5            (soft-link)
    numpy:           1.9.2-py27_0     (soft-link)
    openssl:         1.0.1k-1         (soft-link)
    pip:             7.0.3-py27_0     (soft-link)
    pixman:          0.26.2-0         (soft-link)
    py2cairo:        1.10.0-py27_2    (soft-link)
    pyparsing:       2.0.3-py27_0     (soft-link)
    pyqt:            4.11.3-py27_1    (soft-link)
    python:          2.7.10-0         (soft-link)                                                                                     
    python-dateutil: 2.4.2-py27_0     (soft-link)                                                                                     
    pytz:            2015.4-py27_0    (soft-link)                                                                                     
    qt:              4.8.6-3          (soft-link)                                                                                     
    readline:        6.2.5-1          (soft-link)                                                                                     
    setuptools:      17.1.1-py27_0    (soft-link)                                                                                     
    sip:             4.16.5-py27_0    (soft-link)                                                                                     
    six:             1.9.0-py27_0     (soft-link)                                                                                     
    sqlite:          3.8.4.1-1        (soft-link)                                                                                     
    system:          5.8-2            (soft-link)                                                                                     
    tk:              8.5.18-0         (soft-link)                                                                                     
    zlib:            1.2.8-0          (soft-link)                                                                                     

Proceed ([y]/n)? y                                                                                                                    

Fetching packages ...                                                                                                                 
geos-3.3.3-0.t 100% |#################################################################################################################
ipython-3.1.0- 100% |#################################################################################################################
pip-7.0.3-py27 100% |#################################################################################################################
basemap-1.0.7- 100% |#################################################################################################################
Extracting packages ...                                                                                                               
[      COMPLETE      ]|###############################################################################################################
Linking packages ...                                                                                                                  
[      COMPLETE      ]|###############################################################################################################
#                                                                                                                                     
# To activate this environment, use:                                                                                                  
# $ source activate /tmp/bm_test                                                                                                      
#                                                                                                                                     
# To deactivate this environment, use:                                                                                                
# $ source deactivate                                                                                                                 
#                                                                                                                                     
✔ /tmp                                                                                                                                
13:46 $ source activate /tmp/bm_test
discarding /home/tcaswell/mc/bin from PATH
prepending /tmp/bm_test/bin to PATH
(bm_test) ✔ /tmp 
13:46 $ python bm_scratch.py 

works as expected (where bm_scratch.py is your example).

I suspect that you at some point install mpl using more than one method and there are stale files left around. I suggest starting from a fresh environment (and never working in the 'base' environment).

To try and revive your current env I suggest telling conda to uninstall mpl and basemap, then going into the site-packages folder, then remove matplotlib and mpl_toolkits folders if they still exist, then re-install.

Please ping to have this re-opened if you can reproduce this with a clean environment

@OrbitalMechanic
Copy link
Author

I uninstalled matplotlib and basemap using conda and manually deleted
the matplotlib and mpl_toolkits folders from the site-packages folder.
Then I used conda to install matplotlib and observed that the matplotlib
and mpl_toolkits folders where installed. I re-ran the example and I
still get the same result.

Any suggestions?

P.S. - are you running on a Mac platform or on a linux platform? Please
keep in mind, I'm running on a MacBook Pro running Mac OS X v. 10.10.3.

On 06/21/2015 13:55:00, Thomas A Caswell wrote:

I can not reproduce this issue:

|✔ /tmp 13:45 $ conda create -p bm_test python matplotlib basemap
ipython Fetching package metadata: ...... Solving package
specifications: . Package plan for installation in environment
/tmp/bm_test: The following packages will be downloaded: package |
build ---------------------------|----------------- geos-3.3.3 | 0
14.5 MB ipython-3.1.0 | py27_1 3.4 MB pip-7.0.3 | py27_0 1.4 MB
basemap-1.0.7 | np19py27_0 119.0 MB
------------------------------------------------------------ Total:
138.2 MB The following NEW packages will be INSTALLED: basemap:
1.0.7-np19py27_0 (soft-link) cairo: 1.12.18-4 (soft-link) fontconfig:
2.11.1-4 (soft-link) freetype: 2.5.2-2 (soft-link) geos: 3.3.3-0
(soft-link) ipython: 3.1.0-py27_1 (soft-link) libpng: 1.6.17-0
(soft-link) libxml2: 2.9.0-0 (soft-link) matplotlib: 1.4.3-np19py27_2
(soft-link) ncurses: 5.9-5 (soft-link) numpy: 1.9.2-py27_0 (soft-link)
openssl: 1.0.1k-1 (soft-link) pip: 7.0.3-py27_0 (soft-link) pixman:
0.26.2-0 (soft-link) py2cairo: 1.10.0-py27_2 (soft-link) pyparsing:
2.0.3-py27_0 (soft-link) pyqt: 4.11.3-py27_1 (soft-link) python:
2.7.10-0 (soft-link) python-dateutil: 2.4.2-py27_0 (soft-link) pytz:
2015.4-py27_0 (soft-link) qt: 4.8.6-3 (soft-link) readline: 6.2.5-1
(soft-link) setuptools: 17.1.1-py27_0 (soft-link) sip: 4.16.5-py27_0
(soft-link) six: 1.9.0-py27_0 (soft-link) sqlite: 3.8.4.1-1
(soft-link) system: 5.8-2 (soft-link) tk: 8.5.18-0 (soft-link) zlib:
1.2.8-0 (soft-link) Proceed ([y]/n)? y Fetching packages ...
geos-3.3.3-0.t 100%
|#################################################################################################################
ipython-3.1.0- 100%
|#################################################################################################################
pip-7.0.3-py27 100%
|#################################################################################################################
basemap-1.0.7- 100%
|#################################################################################################################
Extracting packages ... [ COMPLETE
]|###############################################################################################################
Linking packages ... [ COMPLETE
]|###############################################################################################################

# To activate this environment, use: # $ source activate

/tmp/bm_test # # To deactivate this environment, use: # $ source
deactivate # ✔ /tmp 13:46 $ source activate /tmp/bm_test discarding
/home/tcaswell/mc/bin from PATH prepending /tmp/bm_test/bin to PATH
(bm_test) ✔ /tmp 13:46 $ python bm_scratch.py |

works as expected (where |bm_scratch.py| is your example).

I suspect that you at some point install mpl using more than one
method and there are stale files left around. I suggest starting from
a fresh environment (and never working in the 'base' environment).

To try and revive your current env I suggest telling conda to
uninstall mpl and basemap, then going into the site-packages folder,
then remove |matplotlib| and |mpl_toolkits| folders if they still
exist, then re-install.

Please ping to have this re-opened if you can reproduce this with a
clean environment


Reply to this email directly or view it on GitHub
#4546 (comment).

@tacaswell
Copy link
Member

Did you try with a clean environment? Have you installed python or matplotlib using any other method? Do you have PYTHONPATH defined? Where does your python think it is importing mpl_toolkits from?

I suggest you try either the matplotlib-users mailing list or report this as a bug against anaconda.

@efiring
Copy link
Member

efiring commented Jun 21, 2015

I'm trying it on a Mac right now, but with 10.9.5. I will report in a few minutes.

@efiring
Copy link
Member

efiring commented Jun 21, 2015

I had to add conda install pyqt, but then it worked fine, as expected. I am 99.9% sure this has nothing to do with matplotlib as such, or Anaconda, or your OS version. Instead, as @tacaswell suggested, it is caused by some detritus from earlier installations, either on your disk or in your .bash_profile, etc. This is a common problem, and can be hard to track down--but by no means impossible.

@OrbitalMechanic
Copy link
Author

Eric,

Thanks for responding so quickly. If I'm picking up some detritus from
some earlier installation, either on my disk or in my bash_profile file,
what would cause mpl_toolkits not to be found? The folder is in the
site_packages file but I noticed there wasn't an egg file for
mpl_toolkits as there is for matplotlib.

Any suggestions?

Sam Dupree

On 06/21/2015 14:37:40, Eric Firing wrote:

I had to add |conda install pyqt|, but then it worked fine, as
expected. I am 99.9% sure this has nothing to do with matplotlib as
such, or Anaconda, or your OS version. Instead, as @tacaswell
https://github.com/tacaswell suggested, it is caused by some
detritus from earlier installations, either on your disk or in your
.bash_profile, etc. This is a common problem, and can be hard to track
down--but by no means impossible.


Reply to this email directly or view it on GitHub
#4546 (comment).

@jenshnielsen
Copy link
Member

I think the fundamental issue here and in other similar issue is that the directory structure depends on the installation method.

setup.py install will place everything in xxx/site-packages/matplotlib-versionxxx.egg/matplotlib and xxx/site-packages/matplotlib-versionxxx.egg/mpl_toolkits etc. while pip omits the matplotlib-versionxxx.egg directory and places installations in site-packages/matplotlib and site_packages/mpl_toolkits/ I guess you still have some left over incomplete installation that gets picked up

You can check that mpl and mpl|_toolkits are were you expect by doing something like

import matplotlib 
print matplotlib.__file__

Use this to check that matplotlib is imported from where you expect.

and provided that you can import mplot3d you can also do.

import mpl_toolkits.mplot3d
mpl_toolkits.mplot3d.__file__

@WeatherGod
Copy link
Member

The problem is most likely due to an old install of Basemap, since it is
also an "mpl_toolkit". Older versions of Basemap are not compatible with
newer versions of mpl_toolkits due to the switch to setuptools and
namespace packages. Get rid of the old Basemap, and install a new one, and
you should be fine.

On Sun, Jun 21, 2015 at 3:24 PM, Jens Hedegaard Nielsen <
notifications@github.com> wrote:

I think the fundamental issue here and in other similar issue is that the
directory structure depends on the installation method.

setup.py install will place everything in
xxx/site-packages/matplotlib-versionxxx.egg/matplotlib and
xxx/site-packages/matplotlib-versionxxx.egg/mpl_toolkits etc. while pip
omits the matplotlib-versionxxx.egg directory and places installations in
site-packages/matplotlib and site_packages/mpl_toolkits/ I guess you still
have some left over incomplete installation that gets picked up

You can check that mpl and mpl|_toolkits are were you expect by doing
something like

import matplotlib print matplotlib.file

Use this to check that matplotlib is imported from where you expect.

and provided that you can import mplot3d you can also do.

import mpl_toolkits.mplot3d
mpl_toolkits.mplot3d.file


Reply to this email directly or view it on GitHub
#4546 (comment)
.

@jskye
Copy link

jskye commented Apr 29, 2020

this might be happening due to a conflict between nxviz versions of matplotlib and brew installed versions. i was using nxviz and then installed some other libraries on same env using brew and then this occured. would be good if nxviz had a brew repo.

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

6 participants