简体   繁体   中英

Customise the virtualenv `activate` script

What is the conventional way to customise the changes made by a Python virtualenv bin/activate script?

The Python virtualenv is activated by a $VENV/bin/activate script . This script works primarily by setting environment variables specific to the virtualenv.

(This is different from the “bootstrap script” discussed in the Virtualenv documentation . Those are used once, when creating the virtualenv; they are not used when activating the virtualenv. This question is about the activate script.)

Many of the code bases for which I use a Python virtualenv, need additional (custom) environment variables set, at the same time the virtualenv is activated.

  • Edit the $VENV/bin/activate script directly, to add statements that set more environment variables?

  • Write a custom wrapper script, that incidentally calls $VENV/bin/activate ?

  • Write a separate script with a specific name, that will be automatically called by the $VENV/bin/activate script? Does such a thing exist?

Of course I could write a script with a different name, and instruct developers to run that instead. Or I could instruct them to install virtualenvwrapper . But that is not the if-you-got-the-virtualenv-working-then-this-works-too automation that I'm seeking.

Instead, this question is asking how to hook into the existing convention, of activating the virtualenv with a known name $VENV/bin/activate .

How about using virtualenvwrapper and editing $VIRTUAL_ENV/bin/postactivate ? http://virtualenvwrapper.readthedocs.io/en/latest/scripts.html#scripts-postactivate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM