Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switch versions of python

Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.

Question1: How will i tell any framework that go and use version so and so pf python like day django to use 2.6 and say mjango to use 2.4? Something like we say use database databasename kinda syntax.

Question2: Is there more elegant way to switch between version as my hack of symlinking was a virtual disaster?

Question3: Can I download a deb for say hardy and make jaunty believe its for her?

like image 469
dhaval Avatar asked Jul 10 '09 11:07

dhaval


People also ask

How do I switch between versions in python?

Yes, you should be able to switch between python versions. As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed.

Can I have 2 python versions?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.


1 Answers

Use Virtualenv.

There is more information here: Working with virtualenv.

Using virtualenv you can create a new virtual python environment with whatever version of Python you want for each project or application. You can then activate the appropriate environment when you need it.

To expand on my answer:

You can install multiple versions of Python on your computer (I have 2.4, 2.5, 2.6 and 3.1 on my machine - I install each from source). I use a Mac, and keep my system Python as whatever OS X sets as the default.

I use easy_install to install packages. On ubuntu you can get easy_install like this:

sudo apt-get install python-setuptools

To install virtualenv then do:

easy_install virtualenv

I tend to create a new virtualenv for each project I'm working on and don't give it access to the global site-packages. This keeps all the packages tight together and allows me to have the specific versions of everything I need.

virtualenv -p python2.6 --no-site-packages ~/env/NEW_DJANGO_PROJECT

And then whenever I am doing anything related to this project I activate it:

source ~/env/NEW_DJANGO_PROJECT/bin/activate

If I run python now it uses this new python. If I use easy_install it installs things into my new virtual environment.

So, virtualenv should be able to solve all of your problems.

like image 58
DisplacedAussie Avatar answered Oct 10 '22 20:10

DisplacedAussie