使用 virtualenv 和 pip 的工作流程

发布于 2024-10-11 22:35:39 字数 629 浏览 7 评论 0原文

我的系统(Ubuntu 10.x)上已经安装了 python2.6 和 django1.2.3。
这是我在大多数项目中使用的设置。但对于某些项目,我需要沙盒环境、不同的 django 版本、一些额外的 python 模块,有时甚至需要不同的 python 版本。

所以,我现在尝试使用 pip 和 virtualenv,但我无法更改 python 和 django 版本。我是否必须删除默认设置并将所有现有项目移至 1 个 virtualenv 中。我可以避免这种情况吗?即使我这样做,我如何指定不同版本的 python?

如果我必须删除旧的设置。我该怎么做?我目前已将大部分内容安装在 /usr/local/lib/python2.6/dist-packages/ 中,但我不确定其他地方是否也安装了任何内容。

如果我只有 Ubuntu 的完全空白设置,理想的工作流程是什么?是这个吗?

Install python
$ sudo apt-get install python-setuptools 
$ sudo apt-get install python-virtualenv 
$ sudo easy_install pip
$ sudo pip install virtualenvwrapper 

I have python2.6 and django1.2.3 already installed on my system (Ubuntu 10.x).
This is the setup i use for most of my projects. But for some projects I need sandboxed environments, different django version, some extra python modules and sometimes even different python version.

So, I am trying to use pip and virtualenv now,but I am unable to change python and django version. Will I have to remove default setup and move all existing projects into 1 virtualenv. Can I avoid this? Even if I do that, how can I specify a different version of python?

If I have to remove the old settings. How do i do that? I have currently most of the things installed in /usr/local/lib/python2.6/dist-packages/ but I am not sure if there is anything installed anywhere else also.

If I have a completely blank setup with just Ubuntu, what is the ideal workflow? Is it this one?

Install python
$ sudo apt-get install python-setuptools 
$ sudo apt-get install python-virtualenv 
$ sudo easy_install pip
$ sudo pip install virtualenvwrapper 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぃ弥猫深巷。 2024-10-18 22:35:39

您想要执行的操作:

virtualenv --python=/path/to/python/version --no-site-packages ENV_NAME

例如:

virtualenv --python=/usr/bin/python2.6 --no-site-packages my_project_env

如果您在项目中遵循此操作,您应该能够为每个项目进行单独的配置。

You want to do:

virtualenv --python=/path/to/python/version --no-site-packages ENV_NAME

For example:

virtualenv --python=/usr/bin/python2.6 --no-site-packages my_project_env

If you follow this for your projects you should be able to have a separate configuration for each one.

雪花飘飘的天空 2024-10-18 22:35:39

我已经从源代码安装了我需要的每个 Python 版本(2.4、2.5、2.6、2.7、3.1 和 3.2)。这始终是最好的做法,这样就不会弄乱 Python 系统。

我将它们安装在/opt 中。像这样(首先你也需要一堆 Ubuntu 软件包):

./configure --prefix /opt/pythonxx
make -j2; make install # j2 is a nice trick there for dualcores not everyone knows.

然后我为每个版本安装我需要的东西。我从安装Distribute开始:

wget http://nightly.ziade.org/distribute_setup.py
/opt/pythonxx/bin/python distribute_setup.py

(Python 3除外,它需要distribute_setup3.py)
然后我可以安装 pip

/opt/pythonxx/bin/easy_install pip

和 virtualenv:

/opt/pythonxx/bin/pip install virtualenv

(Python 3 的 Virtualenv3 或 virtualenv5)

就是这样!如果我想使用Python 2.4创建一个virtualenv,我会这样做:

/opt/python24/bin/virtualenv foobar

并且Python 2.7:

/opt/python27/bin/virtualenv foobar

运行python只是

/opt/python24/bin/python

等等。除了这些模块和PIL之外,我从不安装上述Python中的任何东西(因为PIL是一个痛苦,但现在有了 Pillow,所以你也不必这样做)。我使用 zc.buildout 和 virtualenv 来保持 python 干净。

I have installed every Python verison I need (which is 2.4, 2.5, 2.6, 2.7, 3.1 and also 3.2) from source. That's always the best thing to do, so you don't mess up the system Python.

I installed them in /opt. Like so (you need a bunch of Ubuntu packages too, first):

./configure --prefix /opt/pythonxx
make -j2; make install # j2 is a nice trick there for dualcores not everyone knows.

Then I for each version install the things I need. I start with installing Distribute:

wget http://nightly.ziade.org/distribute_setup.py
/opt/pythonxx/bin/python distribute_setup.py

(Except for Python 3, who needs distribute_setup3.py)
Then I can install pip

/opt/pythonxx/bin/easy_install pip

And virtualenv:

/opt/pythonxx/bin/pip install virtualenv

(Virtualenv3 or virtualenv5 for Python 3)

And that's it! If I want to make a virtualenv using Python 2.4, I do:

/opt/python24/bin/virtualenv foobar

And Python 2.7:

/opt/python27/bin/virtualenv foobar

Running python is just

/opt/python24/bin/python

Etc. I never install anything in the above Pythons except these modules, and PIL (because PIL is a pain, but now there is Pillow, so you don't have to do that either). I use zc.buildout and virtualenv to keep the pythons clean.

安人多梦 2024-10-18 22:35:39

您可以使用 virtualenv --no-site-packages ENVNAME ,这将确保您的系统 Python 中的默认 Django 不会包含在您的新环境中。

对于不同版本的 Python,您可以按照以下说明进行操作superuser.com 帖子

You can use virtualenv --no-site-packages ENVNAME and that will make sure the default Django in your system Python won't be included in your new environment.

For different versions of Python, you can follow these instructions from a superuser.com post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文