.python-version应该被gitignored的原因是它的版本太具体了。Python的小版本(例如2.7.1 vs 2.7.2)通常彼此兼容,因此您不希望锁定到特定的小版本。此外,许多Python应用程序或库应该使用一系列Python版本,而不仅仅是一个特定版本。使用.python-version表示您希望其他开发人员使用精确的、特定的Python版本,这通常不是一个好主意。在
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:
The PYENV_VERSION environment variable (if specified).
You can use the pyenv shell command to set this environment variable in your current shell session.
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.
The first .python-version file found (if any) by searching each parent directory, until reaching the root of your filesystem.
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-version
应该被gitignored的原因是它的版本太具体了。Python的小版本(例如2.7.1 vs 2.7.2)通常彼此兼容,因此您不希望锁定到特定的小版本。此外,许多Python应用程序或库应该使用一系列Python版本,而不仅仅是一个特定版本。使用.python-version
表示您希望其他开发人员使用精确的、特定的Python版本,这通常不是一个好主意。在如果您想指出所需的最低Python版本,或者其他版本范围,那么我认为在自述文件中记录这一点是更合适的解决方案。在
尽管过于具体,您仍然可以将该文件的版本(意思是:不包括在默认的
.gitignore
)中,如下所示:README
的一个很好的补充,为了说明为特定项目推荐什么版本的pythonpyenv
),也可以简单地忽略(如果您没有pyenv
)。在正如文章“How to manage multiple Python versions and virtual environments ”所述:
但是:
在使用python虚拟环境时,它也可能有点问题,因为人们可能希望使用与
3.7.2/envs/myvenv
不同的虚拟环境名称。在相关问题 更多 >
编程相关推荐