.python Version
If you need your code to behave differently based on the version it's running on, use the sys or platform modules.
: Code runs directly without a separate compilation step and is compatible across Windows, macOS, and Linux [5.4].
: Specify the full patch version (e.g., 3.11.5 instead of just 3.11 ) to avoid subtle discrepancies between minor bug-fix releases across team environments.
Verify the installation:
Notes:
A customized fork built explicitly for Windows execution policies, pyenv-win via GitHub mirrors native terminal commands to help manage standard py.exe launcher path configurations. 3. Conda (Anaconda / Miniconda)
pip freeze > requirements.txt
.python-version file is a plain text file used by tools like pyenv to automatically define the Python version for a specific project directory. It ensures consistent environments across development, testing, and deployment, commonly identifying the desired version for platforms like Heroku. For more details, visit Heroku Dev Center Heroku Dev Center Specifying a Python Version - Heroku Dev Center
When you navigate between different project directories in your terminal, compatible version managers read this file and automatically switch your active shell to the specified Python version. This eliminates the need to manually run version-switching commands every time you change tasks. How the .python-version File Works .python version
cd your-project pyenv local 3.13.13 # Creates .python-version file
pyenv install 3.13.13
To solve this friction, the development community adopted a simple, elegant solution: the .python-version file.
Declares dependency requirements and package metadata (e.g., requires-python = ">=3.10" ). pip , poetry , uv , hatch If you need your code to behave differently
You can dynamically read the file in your automated testing workflows. This prevents duplication by sourcing the version string directly from the repository.
💡 : Always commit .python-version to your Git repository. This acts as documentation for which Python version the codebase supports.
: GitHub Actions can read this file using the python-version-file property in the setup-python action. Python versions | uv - Astral Docs