Tuesday, 27 August 2019

How to Python Code on Interpreter Startup in Virtualenv?

I want to execute code after the python interpreter has started.

We use virtualenv and up to now we had a file called sitecustomize.py which got executed during interpreter start up.

The sitecustomize.py was part of our project. We use the Django definition of this term: It is a small python module which only holds config and nearly no code: Django's Definition of "Project"

Unfortunately some linux distros (Ubuntu) provide a global sitecustomize, and our per virtualenv sitecustomize does not get loaded.

Question

How to run Python code on interpreter startup in a virtualenv?

This code should be executed even if the interactive interpreter gets started.

Goal vs Strategy

I don't care if this hook is called "sitecustomize" or different :-)



from How to Python Code on Interpreter Startup in Virtualenv?

No comments:

Post a Comment