Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Conda environment in pycharm

Conda env is activated using source activate env_name.

How can I activate the environment in pycharm ?

like image 263
Abhinav Rai Avatar asked Mar 12 '17 11:03

Abhinav Rai


People also ask

Can we use Conda environment in PyCharm?

PyCharm supports creating virtual environments for Python with Conda.

How do you select an environment in PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. icon and select Show All. Select the target environment from the list and click OK to confirm your choice.


3 Answers

open

pycharm/preferences/project/Project Interpreter

And check existing interpreter. Conda environments may already be listed there.

enter image description here

If not exists, you can create a new conda environment with "Create Conda Env" button

enter image description here

If you are looking for a specific conda environment you can use 'add local'. When you click 'add local' you will input conda environment path + /bin/python

You can list all conda environment in your system with following commnad.

>>conda info --env
# conda environments:
#
tensorflow            *  /Users/username/miniconda3/envs/tensorflow

you can chose the approach best fits your needs.

like image 191
clockworks Avatar answered Oct 06 '22 23:10

clockworks


The best PyCharm specific answer is this one by wasabi (below).

In general though, if you want to use an interpreter from within a Conda environment then you can change the location of the interpreter to point to the particular environment that you want to use e.g. /home/username/miniconda/envs/bunnies as mentioned in this comment.

However, as mentioned in this answer by Mark Turner, it is possible to have a shell script executed when activating an environment. This method will not run that shell script, but you can follow his workaround if you need that shell script run:

  • open a conda prompt
  • activate the environment
  • run pycharm from the conda prompt
like image 41
Ari Cooper-Davis Avatar answered Oct 07 '22 01:10

Ari Cooper-Davis


As mentioned in one of the comments above, activating an environment can run scripts that perform other actions such as setting environment variables. I have worked in one environment that did this. What worked in this scenario was to:

  • open a conda prompt
  • activate the environment
  • run pycharm from the conda prompt

Pycharm then had access to the environment variables that were set by activating the environment.

like image 12
Mark Turner Avatar answered Oct 07 '22 00:10

Mark Turner