how to know which python version I have and how to switch between them and how to know which version has PyObjC

StackOverflow https://stackoverflow.com/questions/15142936

Frage

I have installed different versions of python during last year. when I open python interpreter, I can see which version I am currently running, But I want to know all the versions I have.

I also want to switch between different python versions. I am using OS X 10.7.5 and this is supposed to have PyObjC built-in. how do I know if my current version of python(the running version) supports PyObjC. are there some specific modules to import and see if PyObjC works in current version.

If the current version (Python 2.7.3) do not access PyObjC but if have PyObjC installed, how will change my current version to link it

Thanks in advance for your help

War es hilfreich?

Lösung

Where have you installed these different versions?

10.7 comes with python 2.5, 2.6, 2.7. I personally use fink, but there is also macports and others for installing libraries. If you want to switch between different versions of python then (unless I'm missing something) you have to call that different python. So you could use /usr/bin/python2.5 or /usr/bin/python2.6 or /usr/bin/python2.7.

I did a quick google search and when I open one of the built-in pythons and run import PyObjCTools that seems to work (and not work in my fink python which is expected). If you have custom installed python environments and you want PyObjC I was suggest reading the manual or rather RTFM. A quick skim looks like you can just do easy_install PyObjC.

Edit to answer your comment:

To add PyObjC to your 2.7.3 you should just have to install it: http://pythonhosted.org/pyobjc/install.html

It doesn't look too complicated, but I've never done it before. Also, note the package dependencies further down the page.

For sharing python modules between python versions...this is probably not a good idea. Unless they are your modules AND pure python AND use compatible syntax between 2.5, 2.6, and 2.7, you shouldn't do this. Some installers are only for a specific version of python or may install things differently depending on what version they are being installed for. You can always install the same packages for each environment with easy_install and pip this isn't difficult at all. But if you really want to I suppose what you could do is make a shared python install directory and add it to your PYTHONPATH:

mkdir ~/my_shared_python
# Add the following line to your .bash_profile or equivalent
export PYTHONPATH=$HOME/my_shared_python:$PYTHONPATH
# You can install packages into there by doing (not sure on the pip syntax):
easy_install -d ~/my_shared_python a_package_im_installing

Then you can run any python you want and it will try to use those modules, but I don't recommend doing this.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top