切换python版本 [英] switch versions of python

查看:204
本文介绍了切换python版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故事: 我拥有的应用程序之一适用于python 2.4,其他适用于2.6.我试图将python2.4链接到python,并且在ubuntu麻烦时事情开始崩溃. 现在,我正在下载2.4的每个依赖项,并使用python2.4 setup.py install进行安装.依赖性似乎是无限的.

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.

问题1:我将如何告诉任何框架去使用版本pf python,例如day django使用2.6并说mjango使用2.4?就像我们说的那样,使用数据库databasename有点语法.

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.

问题2:由于我的符号链接遭到的是虚拟灾难,是否有更优雅的方式在版本之间进行切换?

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

问题3:我可以下载一个耐心的deb并让他开心地为她相信吗?

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

推荐答案

使用 Virtualenv .

此处提供更多信息:使用virtualenv .

使用virtualenv,可以为每个项目或应用程序使用所需的任何Python版本创建一个新的虚拟python环境.然后,您可以在需要时激活适当的环境.

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.

扩展我的答案:

您可以在计算机上安装多个版本的Python(我的计算机上有2.4、2.5、2.6和3.1-我从源代码安装每个版本).我使用Mac,然后将系统Python保留为OS X设置的默认值.

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.

我使用 easy_install 来安装软件包.在ubuntu上,您可以像这样获得easy_install:

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

sudo apt-get install python-setuptools

要安装virtualenv,请执行以下操作:

To install virtualenv then do:

easy_install virtualenv

我倾向于为我正在从事的每个项目创建一个新的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

如果我现在运行python,它将使用这个新的python.如果我使用easy_install,它将把东西安装到新的虚拟环境中.

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

因此,virtualenv应该能够解决您所有的问题.

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

这篇关于切换python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆