0

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?

theo_novak
  • 5
  • 2
  • 3
  • what does `print sys.path` print on ur python prompt? I also don't see any mention of PYTHONPATH variable. You do know that python uses PYTHONPATH to search for modules and not PATH, right? – Kashyap Nov 05 '15 at 16:22
  • "echo $PYTHONPATH" always returned an empty string, even when things worked correctly. If that is the issue, what should I export to PYTHONPATH to get things working, based on the links I provided above? – theo_novak Nov 05 '15 at 16:35
  • Yes. Also what does print sys.path print on ur python prompt? – Kashyap Nov 05 '15 at 16:37
  • print sys.path prints out the following:`['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',` *continued below* – theo_novak Nov 05 '15 at 16:40
  • `'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']` – theo_novak Nov 05 '15 at 16:40

1 Answers1

2

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

Community
  • 1
  • 1
Kashyap
  • 15,354
  • 13
  • 64
  • 103
  • for future reference, the default path that python installs all the modules is conveniently located at /opt/local. Therefore once I `export PYTHONPATH=/opt/local` everything works as expected. Thank you again for your response. – theo_novak Nov 05 '15 at 19:58