Reputation: 5
I have installed python27 and python35 along with a range of packages (pip, numpy, scipy etc.) using brew. I ran python in my terminal and importing worked for every package. However, after I installed python 2.7 and 3.5 using the packages from the website in order to get idle (the non-quartz dependent one), whenever I try to import anything either in idle or the python shell in the terminal I get the following error:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
my .bash_profile looks like this:
`Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"`
"which python" gives me this: /Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I run "ports installed" I receive all of my packages, meaning that everything is there, but the paths are all incorrect. How should I proceed?
Upvotes: 0
Views: 7728
Reputation: 17411
In short, you need to set your PYTHONPATH
correctly.
Here a few nuggets that might help.
Usually 'installers' would install packages under site-packages
subdir somewhere inside python-installation-dir
. These site-packages
are added by python to PYTHONPATH by default (even when your PYTHONPATH is empty), unless you tweaked the python settings as well. Or the installers add the newly installed modules to the PYTHONPATH, either way you don't have to do anything.
It's also possible that while installing somehow you tweaked the installation prefix (folder where stuff is installed), and numpy
etc were installed in some separate directory.
Some libraries install themselves in separate /opt/....
, in which case they would update user's or the global rc scripts to add /opt/..../lib/...
to PYTHONPATH
.
Simplest would be to figure out path where numpy
is installed and update the global or local settings files so that path is included in it.
Some basics: Python - PYTHONPATH in linux and of course: https://www.google.com/search?q=set+PYTHONPATH
Upvotes: 2