Suppose I have a project src code with requirements.txt

I need to create virtualenv. But how to know which pytho version should I use? How to store python version in project, so that others can recreate virtualenv with correct python version?

3 Answers

TonyJafar On

you can set python version in your


more info: Python packaging

dyz On

You can use a Makefile

    virtualenv -p python3 .venv
    .venv/bin/pip install -r requirements.txt || ( \
        virtualenv -p python3 .venv && \
        .venv/bin/pip install -r requirements.txt \
Michael Aaron Safyan On

This depends on your build system and how you are packaging up your application.

If you are deploying the code as a Docker container, the Python version may be encoded in your Dockerfile (specifically, the base image that you use and its associated Python version or how you download and install Python in the creation of your Docker image).

If you are producing a self-contained executable file that extracts the Python interpreter as well as your source files and self-executes, then the specific Python interpreter you download as part of this process is likely how you would encode this (and how to do this may depend on your specific build system).

If you are producing a Python library, one generally does not assume a particular Python version (but rather a range of supported versions) which are determined by the environment in which it is installed (and for which the supported Python versions are not typically encoded directly but merely part of documentation).