How to choose: Macports choose python

When I enter:

port select list python 

This is the result:

 Available versions for python: none python25 (active) python25-apple python26-apple python27 python27-apple 

I thought that when I use python, I will use version 2.5 . Instead, when I enter "python", version 2.7 seems active. How to change this to version 2.5?

 Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 
+23
python version macports
source share
5 answers

Why is this happening

MacPorts installs binaries in /opt/local by default .

There is also preinstalled python on your Mac. When you just type python , it will launch a pre-installed version of python that is not affected by the MacPorts installation.

To find out which version will be executed when just type python, use

 which python 

To launch the Mac port version, use

 /opt/local/bin/python2.5 

Decision

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

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

Port version selection

The first type of port select --list python to indicate the installed version, and then, for example, sudo port select --set python python27 to select 2.7. For more information, enter port help select .

+17
source share

Use

 osx$ port select --list python 

to view available Python installations.

Then use the “--set” option to “select port” to set the port you want to use.

 osx$ sudo port select --set python python27 
+30
source share

Python sets:

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

Python requires a system by default, so it’s best not to enter too much. MacPorts Python is easy to use, since getting packages is so easy.

You can set the link as a shortcut:

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

Then use the MacPorts version from the command line:

 ppython script.py 
+4
source share

Your shell probably caches a python call and no longer looks in PATH. Therefore, when you called python before port select in the same shell session, you need to clear this cache.

For bash, clear the cache with

 hash -r 

or just open a new terminal window.

+3
source share

An alternative is to symlinking each Jupyter binary so that the version number is not displayed:

 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
source share

All Articles