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?
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:
To install virtualenv then do:
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.
And then whenever I am doing anything related to this project I activate it:
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.
Move to the project directory :
Create an environment : virtualenv -p python2.7 --no-site-packages ~/env/twoseven
Then activate your source : source ~/env/twoseven/bin/activate
Pythonbrew is a magical tool. Which can also be called as Python version manager similar to that of RVM-Ruby version manager but Pythonbrew is inspired by Perlbrew.
Pythonbrew is a program to automate the building and installation of Python in the users $HOME.
Before Installing the Pythonbrew, Install “curl” in the machine, to install curl use the below command in the terminal, give the the password for the user when prompted.
After Installing the curl, Now Install Pythonbrew, copy and paste the following commands in the terminal and type the password for the user when prompted.
Recomended method of installation - Easy Install
To complete the installation, type the following command
Alternate method of installation:
Use curl command to download the latest version of pythonbrew from github.
After downloading, change “pythonbrew-install” to “executable”
Then, run the pythonbrew-install in the terminal
Now the Pythonbrew has been installed in the
“Home Directory”
i.e.,/home/user/.pythonbrew
Next, copy and paste the following line to the end of ~/.bashrc
*NOTE: change
“user”
to your user name in the systemThats it! Close the terminal. Steps to Install different versions of Python:
Open a new terminal, type the following command or copy and paste it.
This will install Python 2.6.6 and to install Python 2.7 or Python 3.2, change the version number in the previous command.
or
Update: If you get error while Installing then Install using the below command.
or
How to manage different versions of Python installed in system
For instance, if Python
2.6.6
,Python 2.7
andPython 3.2
is installed in your system, switching between the versions can be done as follows:By default,
Python 2.6.6
will be active and in order to switch to Python 2.7 use the below commandThe default Python is changed to Python 2.7.
Now, to switch to Python 3.2 change the version number in the previous command.
Use the below command to check or list the installed Python versions
Use the below command to check or list the available Python Versions to install
To uninstall any of the installed Python version (for example to uninstall Python 2.7), use the below command.
Use the below command to update the
Pythonbrew
Use the below command to disable the
Pythonbrew
and to activate the default versionEnjoy the experience of installing multiple versions of Python in single Linux / ubuntu machine!
A more grassroot approach than Virtualenv is the side-by-side installation of two Python versions.
If there is an existing installation, and you want a second installation into the same root path (e.g. /usr/local), use this target when making install:
When your second installation is Python 2.6, this will leave you with a /usr/local/bin/python2.6 alongside the old /usr/local/bin/python.
A simple way to switch between these two versions is using a shell alias (alias python=/usr/local/bin/python2.6) on the shell where you invoke the interpreter. But this won't work across sub-shells and she-bang invocations.
I find http://github.com/utahta/pythonbrew much easier to install and use than any other solution.
Just install it and you'll have these options:
Note: if you're using a Linux-based operating system with preinstalled Python, switching (system wide) to another version can make things go wrong, so be careful.
"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?"
You simply run them with the specific python version they need. Run mjango with /usr/bin/python2.4 and django with /usr/bin/python2.6. As easy as that.
"Question2: Is there more elegant way to switch between version as my hack of symlinking was a virtual disaster?"
Yes, see above. Have two separate installs of Python, and run explicitly with the different versions.
"Question3: Can I download a deb for say hardy and make jaunty believe its for her?"
That generally works. If it doesn't, it's because it has dependencies that exist in Hardy, and does not exist in Jaunty, and then you can't.
And here is a Question 4 you didn't ask, but should have. ;)
"Is there an easier way to download all those Python modules?"
Yes, there is. Install setuptools, and use easy_install. It will not help you with library dependecies for those Python modules that have C code and need to be compiled. But it will help with all others. easy_install will download and install all the Python dependencies of the module in question in one go. That makes it a lot quicker to install Python modules.