gpt4 book ai didi

python - 我们应该忽略 .python-version 文件吗?

转载 作者:太空狗 更新时间:2023-10-29 20:13:20 24 4
gpt4 key购买 nike

我有一个 .python-version 文件,当我用 github 创建一个 Python repo 并指定它应该有一个 .gitignore 时,它添加了 .python-version 文件。在我看来,不应忽略该文件,因为在不同机器上运行代码的其他人会想知道他们需要什么版本的 Python。

那为什么是 .gitignored 呢?

最佳答案

虽然过于具体,但您仍然可以对该文件进行版本控制(意思是:不将其包含在默认的 .gitignore 中),如:

  • 它只会被pyenv使用
  • 它是对 README 的一个很好的补充,以说明为特定项目推荐的 python 版本,
  • 它可以很容易地被覆盖(如果你正在使用 pyenv),或者简单地被忽略(如果你没有 pyenv)。

正如文章“How to manage multiple Python versions and virtual environments ”所述:

When setting up a new project that is to use Python 3.6.4 then pyenv local 3.6.4 would be ran in its root directory.
This would both set the version, and create a .python-version file, so that other contributors’ machines would pick it up.

但是:

pyenv looks in four places to decide which version of Python to use, in priority order:

  1. The PYENV_VERSION environment variable (if specified).
    You can use the pyenv shell command to set this environment variable in your current shell session.
  2. The application-specific .python-version file in the current directory (if present).
    You can modify the current directory's .python-version file with the pyenv local command.
  3. The first .python-version file found (if any) by searching each parent directory, until reaching the root of your filesystem.
  4. The global version file. You can modify this file using the pyenv global command.
    If the global version file is not present, pyenv assumes you want to use the "system" Python. (In other words, whatever version would run if pyenv weren't in your PATH.)

关于python - 我们应该忽略 .python-version 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54315206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com