condaminiconda

Is it possible to pass variables to requirements.txt files used by Conda?


I need to install Conda packages from several requirements.txt files (as specified in Conda documentation), and have the versions of the packages be read from environment variables or from another file.

This is an example of how such requirements.txt file could look like:

# requirements.txt
pandas=$pandas_version

So that export pandas_version=1.4.3 will trigger $pandas_version to be replaced by 1.4.3 when running conda install --file requirements.txt.

Is there any way to accomplish this?


Solution

  • It seems to be available since version 10: https://pip.pypa.io/en/stable/reference/requirements-file-format/#using-environment-variables

    You can use ENV variables:

    cat requirements.txt 
    locust==${LOCUST_VERSION}
    
    export LOCUST_VERSION="2.20.1";  pip install  -r requirements.txt
    

    or you can use dotenv file:

    cat .env
    LOCUST_VERSION="2.20.1"
    . ./.env; pip install  -r requirements.txt