Dr. Prof. Patrick
Dr. Prof. Patrick

Reputation: 1374

Cannot add conda environment to Pycharm - Conda executable path is empty even when it's not

I am pretty proficient in pycharm but it is the first time I stumble into this problem.

  1. I created a conda environment
  2. Finding the conda executable which for me is in /home/my_username/.miniconda3/envs/py39/bin/python
  3. Adding it to pycharm results in: enter image description here

I tried to search for this issue and error but the results didnt help. I am using fedora 36 if it is relevant.

Edit: The output of which conda is:

/home/my_username/.miniconda3/condabin/conda

Then trying to add it as the interpreter as suggested in Pycharm: Conda executable path is empty: enter image description here

Upvotes: 8

Views: 35865

Answers (8)

Antonina Belianskaya
Antonina Belianskaya

Reputation: 650

In the path you should define a path to the python.exe in the Conda environment directory.

Here is an example:

Screenshot of Python interpreters in IDE settings

Upvotes: 2

Totomobile
Totomobile

Reputation: 663

On macOS - none of the previous posts fixed the issue. This is the issue:

  • Specify the conda path manually in Pycharm
  • It lists the environments
  • Select one
  • Env is NOT saved as your project interpreter
  • Conda path is not saved.
  • Back to square 0

I tried absolutely everything including completely wiping all JetBrains from all caches, applications settings, everything. It will still not work. The issue is that Pycharm is looking for the conda bin in a specific folder, and it will never work if it's not in the expected folder. Once the conda bin file is in the right location, Pycharm will pick it up automatically.

I fixed it by installing a new copy of conda here:

  • wrong_location: usr/local/anaconda3/ (where conda was installed)
  • right_location: ~/miniconda3/ (where you should install conda/miniconda)

(Download conda here: https://docs.conda.io/projects/miniconda/en/latest/)

When installing conda, pick the 'default' right_location, which is the location that Pycharm expects.

I then migrated my environments by just copying them from wrong_location/envs to right_location/envs.

Start up your Pycharm, and it should now see the conda bin and list your envs, and you can pick from them normally.

Upvotes: 0

Minaise A. Minaise
Minaise A. Minaise

Reputation: 1

If you find yourself unable to add an existing or new Conda environment with all the other answers, I resolved the issue by completely quitting PyCharm all together and re-open it.

Upvotes: 0

MathKid
MathKid

Reputation: 2132

  1. First, check the output of conda env list to find the root folder of your conda env. Then add your conda environment as if it were an existing virtual environment. Provide the full path to the python.exe within the root your conda environment.

  2. Close PyCharm.

  3. Locate your PyCharm settings folder and find the file options\jdk.table.xml. The full path will look something like %AppData%\JetBrains\PyCharm2023.1\options\jdk.table.xml

In there find the element that corresponds to the newly added environment. Then change the tag

<setting name="FLAVOR_ID" value="" /> into <setting name="FLAVOR_ID" value="Conda" />

Upvotes: 0

tyyfkpo
tyyfkpo

Reputation: 136

  1. click the 'add interpreter'-'Add local interpreter';
  2. click 'Conda Environment' on the left panel, browse and select 'yourAnacondaDir\Scripts\conda.exe';
  3. click 'load Environment';
  4. then two options: 'use existing environment' and 'create new environment' show up;
  5. click the first option;
  6. In the 'Use existing environment' box, select 'your_env'

Upvotes: 12

arsalan Yaghoubi
arsalan Yaghoubi

Reputation: 59

As the error mentions either you do not have a Conda installed on your system or the path is not recognized by the IDE. Creating a new project, double check if the bar conda executable: is correctly filled by the directory to the folder Conda is installed on your system.

Normally your IDE fill the conda executable automatically, if this is not the case and manually filling the empty bar did not help, I would recommend to delete and reinstall your conda.

Good Luck

Upvotes: 0

alephzarro
alephzarro

Reputation: 176

You need to first tell PyCharm where conda executable is. This is not so obvious how, as there is no input field for that when adding existing conda environments. IMO it's a UX flaw in PyCharm.

I found this input field only available when creating a NEW conda environment from within a PyCharm. Enter a 'Conda executable' there. In your case: /home/????/.miniconda3/bin/conda

Then I also created a new dummy conda environment so the path is stored and PyCharm is happy. Afterwards, you shouldn't get that "Conda executable path is empty" anymore when adding new conda interpreter.

Upvotes: 1

Dr. Prof. Patrick
Dr. Prof. Patrick

Reputation: 1374

I ended up re-installing the OS and now it works, I would not call it a solution but it is what it is - I couldnt waste more time on this as I have work to do.

Upvotes: 0

Related Questions