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…
这就是正在发生的事情:
- 我创建了一个新文件夹
example_pip_dir
。我进入该文件夹并创建了一个新的pipenv --python 2.7
。 rm -rf example_pip_dir
- 再次创建同名文件夹。
- 我尝试过 ->
pipenv --rm
。它告诉我尚未为该项目创建虚拟环境。 - 我尝试过 ->
pipenv --python 2.7
。它告诉我该项目存在一个虚拟环境,然后继续安装它。
这个不一致是什么?项目的虚拟环境要么存在,要么不存在。就好像对于每个命令,他们在检查虚拟环境时会检查不同的东西。
它应该是一致的,但事实并非如此。
我做错了什么吗?
这对我来说至关重要,因为其中大部分都在 CI(持续集成)系统上运行,因此我不能出现这些不一致的情况,因为用户可能会出于卫生和许多其他原因删除整个项目目录。
CI 内部的情况甚至更糟,因为它甚至会提示我是否要删除它,从而卡住工作人员执行任何其他操作,直到有人添加"is"或“否”。也有点烦人。这可能是因为它本身是在另一个虚拟环境下运行的代理。
最佳答案
这个问题的答案是设置环境变量:
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.
关于python - 如果删除带有 PIPENV 的项目文件夹,当尝试为其创建另一个虚拟环境时,它会告诉您它已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59255894/