Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to: Macports select 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 when I use python I would be using version 2.5. Instead when I enter "python", version 2.7 seems to be active. How do I change that 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.
>>>
like image 207
kadrian Avatar asked Nov 20 '11 13:11

kadrian


3 Answers

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
like image 180
easyE Avatar answered Nov 03 '22 17:11

easyE


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.

like image 31
vidstige Avatar answered Nov 03 '22 17:11

vidstige


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.

like image 9
raimue Avatar answered Nov 03 '22 15:11

raimue