如何在每个项目的基础上设置 PIPENV_VENV_IN_PROJECT

How to set PIPENV_VENV_IN_PROJECT on per-project basis

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

到目前为止,我只看到以下选项有效,none 其中令人满意:

我尝试了以下方法:

那么,如何在每个项目的基础上设置 PIPENV_VENV_IN_PROJECT?

自己来回答这个问题,确实可以!

短篇小说:

只需自己创建一个空的.venv 目录即可。 Pipenv 会自动选择它。

长话短说:

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

但在那一团乱麻中,有一条评论实际上很有帮助:

techalchemy commented on Dec 12, 2018

Things you can do:

  1. Simply create the .venv yourself. Pipenv will use it.
  2. Use a tool like direnv to activate this setting per directory
  3. Set the envvar globally
  4. Create a file in the project root called .venv whose contents are only the path to the root directory of a virtualenv

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

注意:如果你想使用 pipenv 当前 Debian/Stable (Buster),第 4 点将不起作用,因为此功能在后来的 pipenv 版本中引入。但是,第 1 点工作得很好。对于 Python 3,这意味着:

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