How to make python_select work for $$ python command?

I installed a couple of pythons in different versions with macports, and the python 2.6 kernel also works. Now I need to run a program that requires support for the MySQLdb package in python, and this package was installed on the python that I installed macports. The program tells me that MySQLdb is not installed, so I think it is apple python working for this program.

I was looking for some help and found python_select to switch between pythons. However after the command

$>sudo python_select python25 

told me that he chose the python25 version for python when I print

 $>python 

it still runs apple python 2.6.

The question is, how can I get python25 (the one with MySQLdb) to work for the program, not apple python?

Another important thing: the program is NOT a .py file and must be compiled before running. So do I need to reinstall this program? Mac OS Version - Snow Leopard 10.6.

Any answer is appreciated.

+2
python mysql macos
source share
3 answers

By default, MacPorts installs user programs (or links to them) in /opt/local/bin . The MacPorts select_python selects which python instance is associated with /opt/local/bin/python . It does not (and should not) affect what Apple installs in /usr/bin , where the Apple-supplied python and python2.x commands are located.

To invoke MacPorts python2.5, you need to either ensure that /opt/local/bin precedes /usr/bin in your $PATH shell (you can do this by changing your .bash_profile or other shell initialization script) or you can just call desired python with an absolute reference to the path:

 $ /usr/bin/python your-program.py 

Use the default Apple python.

 $ /opt/local/bin/python your-program.py 

to use the version selected with python_select , or:

 $ /opt/local/bin/python2.5 your-program.py 

to explicitly choose MacPorts 2.5.

EDIT:

To change the PATH search to use MacPorts, add this line to .bash_profile :

 export PATH=/opt/local/bin:/opt/local/sbin:$PATH 
+7
source share

First off, I'm not sure with the Mac, because I've never used it before.

but on linux when i do whereis python

It will look like /usr/bin/python /usr/local/bin/python .... etc.

in my .bashrc file, I just export PATH=/usr/local/bin:/usr/bin:$PATH when I want /usr/local/bin more priority

or you can still work like

 /usr/bin/python yourpython.py 

or

 /usr/local/bin/python yourpython.py 

depends on python installation locations.

only my 2 cents. sorry if my answer does not help you.

0
source share

'python' on a mac is just a link. Make "what python", "cd" into the directory where "python" is located, and then run "ls -a py *". You will see where the python also points. If you want python to point to your other version of python, just bind it to the correct version.

0
source share

All Articles