应该在哪里创建 virtualenvs?

编程入门 行业动态 更新时间:2024-10-26 21:28:28
本文介绍了应该在哪里创建 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?

本文发布于:2023-06-09 04:09:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/594948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:virtualenvs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!