How to add the path to conda environment's bin to the $PATH environment variable?

I have a python project with the python interpreter set to python from pre-existing conda environment. The environment is loaded and I can run python commands on the console inside PyCharm. However, when I run a script that requires some additional libraries that are installed in the conda environment, my script fails with an error FileNotFound. This is because my conda environment bin is not present in the $PATH environment variable within PyCharm. However, the $PATH variable in the system includes the bin directory. How do I make the conda bin (/path/to/conda/env/bin) available to the $PATH in PyCharm? 

 

I tried adding $PATH=/path/to/conda/env/bin:$PATH to the environment variables in “Run Config” and a couple of other places, but $PATH on the right-hand side is replaced verbatim instead of expanding the variable. Could anyone please help with setting this variable correctly?

0
6 comments
Official comment

Hi Pooja 

Is the “pre-existing conda environment” the same which has the libraries you are not being able to find ? Please note that the executable python which will be executed by PyCharm is the one configured in the interpreter rather than in $PATH. So if you want to use an environment which has specific libraries you need to point the interpreter of the project to that  conda environment (by creating a new interpreter based on existing conda environment)

 

If the above does not help, I would advise to raise this in a youtrack case so we can have an in depth look

Please provide us: 

- An exact screenshot from the error you are getting. 

- The IDE Logs. (The logs can be provided from Help -> Collect Logs and diagnostics data)

- A description of the environment.

 

Kind regards,

 

Hello, Pooja 

Does it help if you add the required directory to the interpreter paths, according to the procedure described here?

0

Hello. As far as I understand, this is for the python libraries and not the binaries themselves. I am mostly looking to add the executable binaries present in the bin directory of the conda environment.

0

Hi Ervis Velika, I have created a new interpreter pointing to the existing conda environment. The Python version being used is correct, and the environment has all the required libraries. My only problem is with the $PATH variable, which doesn't contain the bin directory of the conda environment. When I echo the $PATH variable from the terminal, I can see the bin directory, but not when I list it via os.environ or in the “Run configurations.” 

0

HI Pooja 

 

Thank you for the clarification 

It seems the issue is related to an existing bug

https://youtrack.jetbrains.com/issue/PY-41166/PyCharm-doesnt-set-PATH-properly-for-conda-venvs-in-USER.conda

In any case to investigate this further I would need some additional information such as output of conda info and 

the IDE Logs (The logs can be provided from Help -> Collect Logs and diagnostics data) on a new youtrack case

 

Kind regards.

 

 

0

Please sign in to leave a comment.