如何根据每个项目设置PIPENV_VENV_IN_PROJECT [英] How to set PIPENV_VENV_IN_PROJECT on per-project basis

查看:177
本文介绍了如何根据每个项目设置PIPENV_VENV_IN_PROJECT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望pipenv为签出项目的每个人自动在 $ PROJECTDIR/.venv 中创建其virtualenv.

I want pipenv to create its virtualenv in $PROJECTDIR/.venv automatically for everyone who checks out the project.

到目前为止,我仅看到以下选项有效,但没有一个令人满意:

So far, I see only the following options working, none of which is satisfying:

  • 要求用户全局设置PIPENV_VENV_IN_PROJECT = 1,迫使我在其他每个项目上都使用我的项目首选项.
  • 请用户在我的项目中时始终通过" PIPENV_VENV_IN_PROJECT = 1 pipenv "调用pipenv,如果他们运行 pipenv 命令而忘记设置<代码> PIPENV_VENV_IN_PROJECT .
  • 要求用户安装第三方工具 direnv 并提供一个 .envrc 文件,从而添加另一个非显而易见的构建依赖项.
  • Ask users to set PIPENV_VENV_IN_PROJECT=1 globally, forcing my project preferences on each of their other projects.
  • Ask users to always invoke pipenv via "PIPENV_VENV_IN_PROJECT=1 pipenv" when inside my project, which begs for trouble if they run a pipenv command and forget to set PIPENV_VENV_IN_PROJECT.
  • Ask users to install a third-party tool direnv and provide an .envrc file, adding yet another non-obvious build dependency.

我尝试了以下方法:

  • 向Pipfile添加类似PIPENV_VENV_IN_PROJECT的选项,但找不到任何此类Pipfile选项.
  • 将" PIPENV_VENV_IN_PROJECT = 1 "放入 $ PROJECTDIR/.env 中,但这仅在 pipenv shell/run ,并且被 pipenv 本身忽略.
  • Add an PIPENV_VENV_IN_PROJECT-like option to Pipfile, but I couldn't find any such Pipfile option.
  • Put "PIPENV_VENV_IN_PROJECT=1" into $PROJECTDIR/.env, but that is only evaluated inside the sub shell of pipenv shell/run, and is ignored by pipenv itself.

那么,如何根据每个项目设置PIPENV_VENV_IN_PROJECT?

So, how do I set PIPENV_VENV_IN_PROJECT on per-project basis?

推荐答案

要亲自回答这个问题,这确实有可能!

To answer this question myself, this is indeed possible!

短篇小说:

只需自己创建一个空的.venv目录.Pipenv会自动将其提取.

Just create an empty .venv directory yourself. Pipenv will pick this up automaticaly.

长话短说:

请注意,pipenv问题跟踪器中有许多问题会给人以错误的印象,即pipenv开发人员不想提供此功能.但是,这些问题只是描述了实现此目标的其他方法,而这些其他方法却被拒绝了.

Note that there are many issues in the pipenv issue tracker that give the wrong impression that the pipenv developers don't want to provide this feature. However, those issues simply describe additional ways to achieve this goal, and those additional ways were declined.

但是在那片混乱中,有一条评论实际上是有帮助的:

But within that mess, there was one comment that was actually helpful:

techalchemy于2018年12月12日发表评论

techalchemy commented on Dec 12, 2018

您可以做的事情:

  1. 只需自己创建.venv.Pipenv将使用它.
  2. 使用direnv之类的工具在每个目录中激活此设置
  3. 全局设置envvar
  4. 在项目根目录中创建一个名为.venv的文件,其内容仅是virtualenv根目录的路径.

对于第1点和第4点,pipenv会自动将其拾取

For points 1 and 4, pipenv will pick this up automatically

注意::如果您想使用当前Debian/Stable(Buster)随附的 pipenv ,第4点将不起作用,因为此功能是在 pipenv 的更高版本.但是,第1点的效果很好.对于Python 3,这意味着:

Note: If you want to use the pipenv shipped with current Debian/Stable (Buster), point 4 won't work, as this feature was introduced in a later pipenv version. However, point 1 works perfectly well. For Python 3, this means:

python3 -m virtualenv -p python3 .venv
pipenv install ...  # resp. pipenv sync

这篇关于如何根据每个项目设置PIPENV_VENV_IN_PROJECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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