如果删除带有 PIPENV 的项目文件夹,当尝试为其创建另一个虚拟环境时,它会告诉您它已经存在

If project folder with PIPENV is deleted, when trying to create another virtual environment for it, it will tell you it already exists

Christopher:example_pip_dir christopher$ pipenv --rm
No virtualenv has been created for this project yet!
Aborted!
Christopher:example_pip_dir christopher$ pipenv --python 2.7
Virtualenv already exists!
Removing existing virtualenv…
Creating a virtualenv for this project…
Pipfile: /Users/christopher/example_pip_dir/Pipfile
Using /usr/local/bin/python (2.7.16) to create virtualenv…
⠴ Creating virtual environment...Already using interpreter /usr/local/opt/python@2/bin/python2.7
New python executable in /Users/christopher/.local/share/virtualenvs/example_pip_dir-WYuRpNkV/bin/python2.7
Also creating executable in /Users/christopher/.local/share/virtualenvs/example_pip_dir-WYuRpNkV/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /usr/local/bin/python

✔ Successfully created virtual environment! 
Virtualenv location: /Users/christopher/.local/share/virtualenvs/example_pip_dir-WYuRpNkV
Creating a Pipfile for this project…

事情是这样的:

  1. 我创建了一个新文件夹 example_pip_dir。我进入文件夹并创建了一个新的 pipenv --python 2.7.
  2. rm -rf example_pip_dir
  3. 再次创建同名文件夹。
  4. 我试过了 -> pipenv --rm。提示我这个项目还没有创建虚拟环境。
  5. 我试过了 -> pipenv --python 2.7。它告诉我这个项目存在一个虚拟环境,然后继续安装它。

这种不一致是什么?项目的虚拟环境是否存在。就好像对于每个命令,他们在检查虚拟环境时会检查不同的东西。

应该是一致的,这个不是。

我是不是做错了什么?

这对我来说很重要,因为其中大部分是 运行 在 CI(持续集成)系统上,因此我不能有这些不一致,因为用户可能会删除他们的整个项目确实出于卫生和许多其他原因的目录。

在 CI 里面更糟糕,因为它甚至会提示我是否要删除它,让工作人员无法做任何其他事情,直到有人添加是或否。也有点烦人。可能是因为它是 运行 在另一个虚拟环境下本身的代理。

实际上删除文件夹没有任何效果,因为只有名称用于生成 virtualenv 哈希。可能发生的情况是 rm 命令正在寻找 Pipfile,但没有找到,只是说没有 virtualenv。当实际上 virtualenv 存在并在您再次安装它时立即找到它。

我做了很多假设,因为缺少一些信息。如果您用详细信息更新您的问题,我很乐意提供进一步的帮助。

这个问题的答案是设置环境变量:

PIPENV_YES=True

https://pipenv.kennethreitz.org/en/latest/advanced/#pipenv.environments.PIPENV_YES

If set, Pipenv automatically assumes “yes” at all prompts. Default is to prompt the user for an answer if the current command line session if interactive.