应该在哪里创建 virtualenvs? [英] Where should virtualenvs be created?

查看:63
本文介绍了应该在哪里创建 virtualenvs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道应该把我的虚拟环境放在哪里.

I'm confused as to where I should put my virtualenvs.

在我的第一个 django 项目中,我使用命令创建了该项目

With my first django project, I created the project with the command

django-admin.py startproject djangoproject

然后我 cd 进入 djangoproject 目录并运行命令

I then cd'd into the djangoproject directory and ran the command

virtualenv env

它创建了与内部 djangoproject 目录处于同一级别的虚拟环境目录.

which created the virtual environment directory at the same level as the inner djangoproject directory.

这是为该特定项目创建 virtualenv 的错误位置吗?

Is this the wrong place in which to create the virtualenv for this particular project?

我的印象是,大多数人将他们所有的 virtualenv 放在一个完全不同的目录中,例如~/virtualenvs,然后使用 virtualenvwrapper 在它们之间来回切换.

I'm getting the impression that most people keep all their virtualenvs together in an entirely different directory, e.g. ~/virtualenvs, and then use virtualenvwrapper to switch back and forth between them.

有没有正确的方法来做到这一点?

Is there a correct way to do this?

推荐答案

很多人使用 virtualenvwrapper 工具,它将所有 virtualenv 保存在同一个位置(~/.virtualenvs 目录),并允许创建和保存它们的快捷方式.例如,您可能会这样做:

Many people use the virtualenvwrapper tool, which keeps all virtualenvs in the same place (the ~/.virtualenvs directory) and allows shortcuts for creating and keeping them there. For example, you might do:

mkvirtualenv djangoproject

然后:

workon djangoproject

将 virtualenv 目录保留在项目本身中可能是个坏主意,因为您不想分发它(它可能特定于您的计算机或操作系统).相反,使用 pip 保留一个 requirements.txt 文件:

It's probably a bad idea to keep the virtualenv directory in the project itself, since you don't want to distribute it (it might be specific to your computer or operating system). Instead, keep a requirements.txt file using pip:

pip freeze > requirements.txt

然后分发.这将允许使用您的项目的其他人将所有相同的要求重新安装到他们的 virtualenv 中:

and distribute that. This will allow others using your project to reinstall all the same requirements into their virtualenv with:

pip install -r requirements.txt

这篇关于应该在哪里创建 virtualenvs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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