How to make python_select work for '$>python' command?
macos, mysql, python
Solution
By default, MacPorts installs user programs (or links to them) in `/opt/local/bin`. The MacPorts `select_python` command selects which python instance is linked to `/opt/local/bin/python`. It has no effect (nor should it) on what Apple installs in `/usr/bin`, which is where the Apple-supplied `python` and `python2.x` commands are.
To invoke the MacPorts python2.5, you either need to ensure that `/opt/local/bin` precedes `/usr/bin` on your shell `$PATH` (you can do this by modifying your `.bash_profile` or other shell initialization script) or you can simply invoke the desired python with an absolute path reference:
$ /usr/bin/python your-program.py
to use the Apple-supplied default 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 select the MacPorts 2.5 one.
EDIT:
To modify your search PATH to use MacPorts, add this line to `.bash_profile`:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Problem
I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, so I guess it is the apple python working for that program. I searched for some help and found python_select for switching between pythons. However after the command ``` $>sudo python_select python25 ``` told me that it selected the version "python25" for python, when I type ``` $>python ``` it is still apple python 2.6 that launches. The question is that how can I make python25(the one with MySQLdb) work for the program rather than apple python? Another important thing, the program is NOT a .py file and needs to be compiled before running. So do I need to re-install this program? My Mac OS version is Snow Leopard 10.6. Any answer is appreciated.