简体   繁体   English

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

[英]How does pipenv decide my python version and why does the requirement.txt generated different from the original?

How does pipenv decide my python version? pipenv 如何决定我的 python 版本? My default python3 version is different from the version pipenv decided.我的默认 python3 版本与 pipenv 决定的版本不同。 A simple example to illustrate my problem.一个简单的例子来说明我的问题。 Pipefile said 3.8 while my python3 is 3.9. 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

Another problem I found is the requirement.text it generated was different from the one created Pipefile in the first place.我发现的另一个问题是它生成的 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

Comparing with my requirements.txt that generated the Pipefile in the first place it added ptyprocess.与我的 requirements.txt 相比,它首先生成了 Pipefile,它添加了 ptyprocess。 As the comment pointed out ptyprocess is used by pexpect.正如评论指出的 ptyprocess 被 pexpect 使用。 But why did Pipefile add that as another requirement.但是为什么 Pipefile 将其添加为另一个要求。

Looking at the pipenv docs on specifying a python version it states:查看有关指定 python 版本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 版本,则 [requires] python_full_versionpython_version将自动选择,在执行时回退到系统的默认 python 安装。

My guess is you initialized your pipenv project before you upgraded to python 3.9.我的猜测是你在升级到 python 3.9 之前初始化了你的pipenv项目。

If you do want to update your Pipfile to specify your specific version of python you can simply:如果您确实想更新您的Pipfile以指定 python 的特定版本,您可以简单地:

pipenv --python 3.9

You can of course also manually update the python_version in your Pipfile .您当然也可以手动更新python_version中的Pipfile

I opened an issue against pipenv https://github.com/pypa/pipenv/issues/4546 , after discussing with one of maintainers, I now understood why my problem happened.我打开了一个针对 pipenv https://github.com/pypa/pipenv/issues/4546的问题,在与一位维护人员讨论后,我现在明白了为什么会发生我的问题。

For my first issue, when run pipenv install pipenv reused the existing one which was python 3.8, ie venv is not recreated.对于我的第一个问题,当运行pipenv install pipenv 重用了现有的 python 3.8 时,即未重新创建 venv。 I feel it looks like a problem, why reuse a venv on a new project?我觉得这看起来像个问题,为什么要在新项目中重用 venv?

For my second issue, it does help me understand what does " produce deterministic builds " mean.对于我的第二个问题,它确实帮助我理解了“产生确定性构建”的含义。 ptyprocess is used by pexpect. ptyprocess 由 pexpect 使用。 I check pexpect's setup.py https://github.com/pexpect/pexpect/blob/master/setup.py我检查了 pexpect 的 setup.py https://github.com/pexpect/pexpect/blob/master/setup.py

install_requires=['ptyprocess>=0.5'],

So by specifying ptyprocess==0.6.0 & pexpect==4.8.0 in requirement.txt does produce deterministic build.因此,通过在 requirements.txt 中指定ptyprocess==0.6.0 & pexpect==4.8.0确实会产生确定性构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 requirements.txt 文件中选择特定版本 - how to pick a particular version from requirement.txt file 如何使用 anaconda 从 python 中的 Requirement.txt 安装包? - How to install packages from Requirement.txt in python using anaconda? python中的Requirement.txt文件 - Requirement.txt file in python 如何使用python脚本安装Django项目requirements.txt - How can install Django project requirement.txt with python script 为什么 dockerfile 中的 requirements.txt 空白 - why blank requirement.txt in dockerfile 如何获得readthedocs.org构建以忽略我的require.txt? - How can I get readthedocs.org build to ignore my requirement.txt? 如何使用空闲的 python 将requirements.txt 中提到的所有 python 包下载到 linux 的文件夹中? - how to download all the python packages mentioned in the requirement.txt to a folder in linux using python idle? 如何知道python模块正在使用哪个子模块? 无法为 docker 镜像创建requirement.txt - How to know which sub module are in use with python module?? unable to create requirement.txt for docker image 如何将required.txt中提到的所有python包下载到linux的文件夹中? - how to download all the python packages mentioned in the requirement.txt to a folder in linux? 未安装require.txt中的依赖项 - Dependency in requirement.txt not installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM