Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

development environment - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...