Locate MacPorts package?

前端 未结 6 2012
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 21:18

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

6条回答
  •  眼角桃花
    2020-12-09 21:48

    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.

提交回复
热议问题