I just installed the py27-numpy package via MacPorts and python will not find the module when I use this command: import scipy
I used the help(\'m
Your PATH is incorrect. It appears to be picking up another Python 2.7, likely one installed using a binary installer from python.org or elsewhere, and not the MacPorts installed one. Try removing the the /Library/Frameworks/Python.framework/Versions/2.7/bin
from PATH or just invoke the MacPorts Python directly:
/opt/local/bin/python2.7
sudo port select --set python python27
is the best answer to install port's python system-wide
Based on Jeremy W. Sherman's answer
I checked my python version
python --version
Python 3.8.5
and location:
which python
/opt/local/bin/python
and then tried:
sudo port contents python38
which lists 7285 lines:
Port python38 contains:
/Applications/MacPorts/Python 3.8/IDLE.app/Contents/Info.plist
/Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/IDLE
/Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/Python
/Applications/MacPorts/Python 3.8/IDLE.app/Contents/PkgInfo
...
/opt/local/share/man/man1/python3.8.1
combining that with fardjad's answer leads to:
sudo port contents python38 | grep site-packages
with the output:
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/README.txt
since we need the directory modifying the command to:
dirname $(sudo port contents python38 | grep site-packages)
gives the desired directory:
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
so it's possible to end up with the one-liner:
One-Line PYTHONPATH setting in macports:
export PYTHONPATH=$(dirname $(sudo port contents python38 | grep site-packages))
and we can check the result:
echo $PYTHONPATH
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
For reference see how the Eclipse Liclipse python IDE dialog for setting the PATH looks - there are some more directories you might want to include for a fully specified PYTHONPATH.
To find the location of installed components, use the contents
subcommand:
port contents py27-numpy
As for getting python
to find the package, see @fardjad's response.
MacPorts should install Python packages in /opt/local/Library/Frameworks/Python.framework/2.7/site-packages
by default. So make sure to set $PYTHONPATH
environment variable in your .profile
file:
export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/site-packages"
With Homebrew only using the latest, the Mac system version, and MacPorts for the others in-between, I was confused until I found python locations differ depending on the installer.
Here's an opinionated tip: Use virtualenvs for your projects and don't change your default version with the MacPorts. I won't and don't want to remember to updoot my python in the middle of something so I rely on virtualenvs. Choose and find the python version on the computer, then mkvirtualenv --python=/found/u/python3.X getawesome
.