dreo
dreo

Reputation: 950

Anaconda environment in Pycharm

I am trying to use Anaconda environment as an interpreter in Pycharm.

It actually works, but it's extremely slow - even running a single line "hello world" takes like 5 sec.

I guess the reason is Pycharm trying to activate the environment before every execution of the script and activation in Anaconda is generally slow (at least from my experience).

The execution speed is ok when using Anaconda root env. or when using virtualenv. Any idea/workaround how to speed it up?

Upvotes: 7

Views: 12203

Answers (2)

Juan Leni
Juan Leni

Reputation: 7638

You should not activate the environment on every run. You need to define the interpreter for the project. It will take a couple of seconds to parse the installed packages in that environment and later it will be fast.

https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#project-interpreter

I wonder if there is something special in the packages you have in your environment. Five seconds is not normal.

Have you tried creating a new environment from pycharm?

https://www.jetbrains.com/help/pycharm/conda-support-creating-conda-environment.html

and later adding the packages that you really need for that project?

Upvotes: 5

dreo
dreo

Reputation: 950

Looks like I'm not the first one experiencing this. A cool guy named Guilherme Melo created wrappers which you can use as an replacement for python interpreter in Pycharm. These wrappers than handle environment activation in a much faster way.

Just follow his advices here.

Basically all you need is to install a package called conda-wrappers into you conda environment a then replace the interpreter in Pycharm.

conda create -n test python
source activate test
conda install -c conda-forge conda-wrappers

Works in Windows too. So instead of <env>/python.exe you should select <env>/Scripts/wrappers/conda/python.bat.

That said, I consider this to rather be a workaround for a very slow conda activation script - would be nice to have that handled in a first place.

Upvotes: 4

Related Questions