Confused about virtualenvs - need to set a lot of environment vars

Hi, I'm pretty new to PyCharm and I'm evaluating it for use with a large-ish commercial Python project.  This project has been around a long time (circa 1998) and doesn't always do things the typical Python way.

In this project you have to define a bunch of environment variable configuration to get anything done such as run unit tests or to run most of the commands provided by the program.  We've got these variables collected in a setup file that must be sourced before doing anything.  We have our own virtualenv-like script that launches a suitable environment and sources that file, similar to "activate" in virtualenv.

I'm trying to figure out how to include this setup step in actions launched from PyCharm, particularly Run/Debug/Test configurations.  It might be possible to just set all those environment variables in each run configuration I create, but that seems really sub-optimal.  I'd prefer to maintain everything in my "setup" file so I don't have to change a bunch of project settings when something changes there.

I created a virtualenv for my project and set that as the project interpreter.  Editing the "activate" script inside the virtualenv directory to source my setup file seemed like a logical step, and indeed this works fine when sourcing activate from a command line.  However when doing a Run from within PyCharm, it just runs the python binary inside the virtualenv directly without sourcing the activate script, so my variables don't get set.

So what's a good or standard way to get my setup file sourced? Maybe replace the virtualenv python executable with a script that sources my setup file first?  Thanks in advance for any suggestions!
1 comment
Hi Preston,

You could write a script which run python.exe file with your environment variables set. Please give to this script a standard name of Python executable file and set this script as project interpreter.

There is a feature request to load environment variables from file: http://youtrack.jetbrains.com/issue/PY-5543. Please vote for it to get this feature implemented and receive updates on this issue.
0

Please sign in to leave a comment.