Weber Huang
Weber Huang

Reputation: 373

PyCharm project cannot add poetry interpreter

I have tried to build a new PyCharm project by poetry environment, enter image description here while setting up it showed enter image description here

and cannot setup the interpreter. Have anyone got the similar problem before and know how to solve this error?

Update
I have upgraded the PyCharm version to PyCharm Professional 2022.1.1 and the problem still remain.

Upvotes: 7

Views: 17268

Answers (3)

kingaj
kingaj

Reputation: 791

The suggestion by @Natacha is helpful, but didn't complete the job for me. My own personal fails had to do with accepting Pycharm recommendations for the location of the poetry and python binaries. Be sure to get them right! In the Pycharm terminal (in my case, Gitbash):

# Location of python from pyenv     
pyenv which python
# Location of poetry binary 
which poetry

Paying attention to the details saves a lot of grief :)

Upvotes: 0

Natacha
Natacha

Reputation: 1250

This happened to me when using pyenv and having selected a local Python for that project directory different from the one used to install Poetry. So, this makes pythons local (Pyenv set for project) adn poetry selected (the one used to install) are not found by PyCharm.

Solution

Change Poetry's config (in my case global, but you can by project) to take always the active Python instead of the Poetry installed one.

  1. Check the config list for Poetry poetry config --list
  2. Look for the item virtualenvs.prefer-active-python(default is false)
  3. Set it to true with poetry config virtualenvs.prefer-active-python true

Check that took effect repeating step 1.

Try again on PyCharm.

Upvotes: 3

Weber Huang
Weber Huang

Reputation: 373

Alright, I have fixed this problem.

Below is my debug steps, hope it can help those who are struggling in the same situation:

  1. Posting a support report to PyCharm team with no responce
  2. Searching for a lot of posts from communities
  3. Creating a poetry project by terminal
  4. Inside the project directory, I tried poetry env info and it showed that the local virtualenv is NA
  5. Trying to create one by poetry env use $(which python), yet it returned Skipping virtualenv creation, as specified in config file and this answer gave me a hint.
  6. Typing poetry config --list and it showed that virtualenvs.create = false
  7. Trying to enable the virtualenv creation by the command poetry config virtualenvs.create true
  8. Restarted the PyCharm IDE and tried to add the interpreter again and it WORKED!!

I am not sure if the command poetry config virtualenvs.create true is permant or not.

Upvotes: 11

Related Questions