Detect venv in the project folder

We create our environment through scripts, this does the following :


Clones the required projects.

Clones project settings.

Creates the python virtual environment


Issue is how do I automatically get Pycharm to use the venv on the target machine, can I configure a path in the settings that is relative to the root ?

Or a standard path from the root, like ~/project/venv


We have the python system interpreter in a standard location on all machines.


Comment actions Permalink

You can just create a new interpreter, select "Virtualenv > Existing environment", and point to the python executable inside a venv directory. PyCharm should detect and activate venv automatically for this project.

Or, do you want to script that as well?

Comment actions Permalink

I'd like to script it, we are working on macos. So ideally I'd liek to be able to piut a path into the settings like



Or have a relative path in the project settings like


Which will then force the python interpreter to be called from that point.

Creating a new one works file until you come to create a new environment that has the same name as an existing environment, this then causes an issue wit h the second virtualenv unsure of how to solve this,

Comment actions Permalink

Not sure if it's possible to use relative paths for interpreter settings, probably not.

The interpreter settings are stored in "config\options\jdk.table.xml" (see here for where to find the config dir:

You might be able to change config directly using scripts, but this hasn't been tested and I can't guarantee it'll work.

Not sure why you would create a second interpreter with the same name. Having multiple duplicate interpreters may cause issues, but you can use one interpreter for multiple projects, so I don't see a reason to create duplicate interpreters, unless I misunderstood something about your case.

Comment actions Permalink

the python environment name seems to be defined by the folder that it is in.(name is in the ./idea folder in a project)

When creating a new environment we rename the older one with a timestamp so if required we can look back at it.


However the name of the virtualenv is in the .idea folder and the realy path that this is on seem to be in the user settings, this means that old environment is not longer poionting at it's virtualenv but the new enivonments vitualenv.

in general if you move a pycharm project on disk you need to setup the virtualenv again in any case.


Please sign in to leave a comment.