M. Wang
M. Wang

Reputation: 13

mac pre-bundled python and newly-installed one

I'm trying to install python and its library in bash, using brew and pip.

When I type command

pip list

it seems that numpy(1.8.0rc1), matplotlib(1.3.1), scipy(0.13.0b1) are all installed. However, when I type ipython command and enter the interactive python interface,

import numpy

works fine, but

import matplotlib
import scipy

run into error saying that "ModuleNotFoundError".

I think it is because OS has its own pre-bundled python and pip list command shows what libraries are installed for the pre-bundled one. But ipython command enters into the newly-installed python where those two libraries are not installed.

So could any one talk about the two pythons, and how could I install the library to the correct position and enter the proper python.

I've tried brew, reinstall, pip, sudo and they didn't work quite well. BTW, when type print(sys.path) in ipython, it gives

['', '/usr/local/Cellar/ipython/6.2.1/libexec/bin', '/usr/local/Cellar/ipython/6.2.1/libexec/lib/python3.6/site-packages', '/usr/local/Cellar/ipython/6.2.1/libexec/vendor/lib/python3.6/site-packages', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages', '/usr/local/Cellar/numpy/1.13.3/libexec/nose/lib/python3.6/site-packages', '/usr/local/Cellar/ipython/6.2.1/libexec/lib/python3.6/site-packages/IPython/extensions', '/Users/bazinga/.ipython']

Upvotes: 0

Views: 158

Answers (1)

hoefling
hoefling

Reputation: 66311

The reason behind this is that you now have two Python installations, one being the system one:

$ python -V
Python 2.7.13

and the other one installed via Homebrew ("brewed" Python):

$ python3 -V
Python 3.6.3

When you issue pip list, you are listing packages installed for the system Python. You can check what Python installation does pip belong by issuing pip -V. The package manager for the brewed Python is pip3, check this: pip3 -V. All the commands valid for pip will also work with pip3, for example list packages by issuing pip3 list etc.

The ipython Installation uses the brewed Python, so in order to install packages so be accessible by ipython, use pip3:

$ pip3 install --user numpy matplotlib scipy

Upvotes: 1

Related Questions