How to: Macports select python

后端 未结 5 1349
感动是毒
感动是毒 2020-11-28 06:26

When I enter:

port select --list python

This is the result:

Available versions for python:
    none
    python25 (active)
         


        
相关标签:
5条回答
  • 2020-11-28 07:07

    Python installs to:

    • Default (Apple): /usr/local/bin
    • MacPorts: /opt/local/bin
    • python.org: /Library/Frameworks/python...

    Default python is required by system so best not to mess with it too much. MacPorts Python convenient to use because getting packages so easy.

    You can set link as shortcut:

    sudo ln -s /opt/local/bin/python /usr/local/bin/ppython
    

    Then from command-line to use MacPorts version:

    ppython script.py
    
    0 讨论(0)
  • 2020-11-28 07:18

    Use

    osx$ port select --list python
    

    to list your available Python installations.

    Then use the "--set" option to "port select" to set the port you wish to use.

    osx$ sudo port select --set python python27
    
    0 讨论(0)
  • 2020-11-28 07:20

    Why this happens

    MacPorts installs binaries into /opt/local by default.

    There is also a preinstalled python on your Mac. When just typing python to start, it will start the preinstalled python version not affected by MacPorts install.

    To see what version will be executed when just typing python use

    which python
    

    To start the mac ports version use

    /opt/local/bin/python2.5
    

    Solution

    If you wish to always use MacPorts binaries you can change your path so that /opt/local/bin appears before /use/local/bin etc.

    /opt/local/bin etc. are added in ~/.tcshrc by MacPorts. Also be sure to look in ~/.profile and ~/.bash_profile as these are default on mac.

    Selecting version in ports

    First type port select --list python to list installed version, then just for example sudo port select --set python python27 to select 2.7. For more information type port help select.

    0 讨论(0)
  • 2020-11-28 07:21

    An alternative is symlinking each and every Jupyter binary so that the version number does not appear:

    cd /opt/local/bin
    JUPYTER_VERSION=2.7
    for a in jupyter*$JUPYTER_VERSION; do sudo ln -s $a $(echo $a | sed -e 's:-'$JUPYTER_VERSION':g'); done
    
    0 讨论(0)
  • 2020-11-28 07:22

    Your shell probably caches the invocation of python and does not look in PATH again. So, when you called python before port select in the same shell session, you need to clear this cache.

    For bash, clear the cache using

    hash -r
    

    or simply open a new terminal window.

    0 讨论(0)
提交回复
热议问题