[英]How does pipenv decide my python version and why does the requirement.txt generated different from the original?
pipenv 如何決定我的 python 版本? 我的默認 python3 版本與 pipenv 決定的版本不同。 一個簡單的例子來說明我的問題。 Pipefile 說 3.8 而我的 python3 是 3.9。
pyenv_test ➤ cat requirements.txt
pexpect==4.8.0
termcolor==1.1.0
pyenv_test ➤ pipenv install
requirements.txt found, instead of Pipfile! Converting...
✔ Success!
Warning: Your Pipfile now contains pinned versions, if your requirements.txt did.
We recommend updating your Pipfile to specify the "*" version, instead.
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✔ Success!
Updated Pipfile.lock (a46966)!
Installing dependencies from Pipfile.lock (a46966)...
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
pyenv_test ➤ cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pexpect = "==4.8.0"
termcolor = "==1.1.0"
[dev-packages]
[requires]
python_version = "3.8"
pyenv_test ➤ which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
我發現的另一個問題是它生成的 requirements.text 與最初創建的 Pipefile 不同。
pyenv_test ➤ pipenv lock -r
#
# These requirements were autogenerated by pipenv
# To regenerate from the project's Pipfile, run:
#
# pipenv lock --requirements
#
-i https://pypi.org/simple
pexpect==4.8.0
ptyprocess==0.6.0
termcolor==1.1.0
與我的 requirements.txt 相比,它首先生成了 Pipefile,它添加了 ptyprocess。 正如評論指出的 ptyprocess 被 pexpect 使用。 但是為什么 Pipefile 將其添加為另一個要求。
查看有關指定 python 版本的pipenv
文檔,它指出:
如果您未在命令行上指定 Python 版本,則 [requires]
python_full_version
或python_version
將自動選擇,在執行時回退到系統的默認 python 安裝。
我的猜測是你在升級到 python 3.9 之前初始化了你的pipenv
項目。
如果您確實想更新您的Pipfile
以指定 python 的特定版本,您可以簡單地:
pipenv --python 3.9
您當然也可以手動更新python_version
中的Pipfile
。
我打開了一個針對 pipenv https://github.com/pypa/pipenv/issues/4546的問題,在與一位維護人員討論后,我現在明白了為什么會發生我的問題。
對於我的第一個問題,當運行pipenv install
pipenv 重用了現有的 python 3.8 時,即未重新創建 venv。 我覺得這看起來像個問題,為什么要在新項目中重用 venv?
對於我的第二個問題,它確實幫助我理解了“產生確定性構建”的含義。 ptyprocess 由 pexpect 使用。 我檢查了 pexpect 的 setup.py https://github.com/pexpect/pexpect/blob/master/setup.py
install_requires=['ptyprocess>=0.5'],
因此,通過在 requirements.txt 中指定ptyprocess==0.6.0 & pexpect==4.8.0
確實會產生確定性構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.