pipenv如何决定我的python版本,以及为什么生成的requirement.txt与原始版本不同?

2024-06-18 13:12:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我发现的另一个问题是它生成的requirement.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

与最初生成管道文件的my requirements.txt相比,它添加了ptyprocess。正如评论所指出的,pexpect使用ptyprocess。但为什么Pipefile会将其作为另一项要求添加


Tags: runtest版本txtlockpyenvpackagespipenv
2条回答

查看specifying a python version上的pipenv文档,它指出:

If you don’t specify a Python version on the command–line, either the [requires] python_full_version or python_version will be selected automatically, falling back to whatever your system’s default python installation is, at time of execution.

我猜您在升级到python 3.9之前初始化了pipenv项目

如果要更新Pipfile以指定特定的python版本,只需执行以下操作:

pipenv  python 3.9

当然,您也可以手动更新python_version中的Pipfile

我对pipenvhttps://github.com/pypa/pipenv/issues/4546提出了一个问题,在与一名维护人员讨论之后,我现在明白了问题发生的原因

对于我的第一个问题,当runpipenv installpipenv重用现有的python3.8时,即不会重新创建venv。我觉得这看起来像个问题,为什么要在新项目上重用venv

对于我的第二个问题,它确实帮助我理解“生成确定性构建”的含义。pexpect使用ptyprocess。我检查pexpect的setup.pyhttps://github.com/pexpect/pexpect/blob/master/setup.py

install_requires=['ptyprocess>=0.5'],

因此,通过在requirement.txt中指定ptyprocess==0.6.0 & pexpect==4.8.0,确实可以生成确定性构建

相关问题 更多 >