PyCharm with Pyenv

Solution 1:

In Pycharm version 2017.3, you can go to Pycharm -> Preferences -> Project -> Project Interpreter -> <project_name> -> settings button on the right of the python interpreter text box -> Add local

This will open a new window with virtualenv Environment as one of the options on the left. On Selecting it, you will get an option to make a new virtualenv environment or use an existing virtual environment. Here next to the dropdown text box, you can click "..." and browse to your existing virtualenv created using pyenv and select it. It will select this virtualenv when you start terminal from Pycharm and also use the corresponding python interpreter as set while creating that virtualenv.

enter image description here

Solution 2:

Get pyenv-virtualenv plugin for more project-specialized environments.

Then, create a new environment for project: (assume that we installed python-3.7.1 with pyenv and we'll use it)

$ pyenv virtualenv 3.7.1 projectName-3.7.1

This command generates folder for our environment.

Open pyCharm (v2018.3.1 used):

Create New Project > Existing Interpreter

Now you can type path of your environment:

~/.pyenv/versions/projectName-3.7.1/bin/python3

Then press Create.. That's all.

If there is already exists project:

File > Settings > Project: projectName > Project: Interpreter

Again, you can type path of the environment as like above. So you will see packages installed on this environment.

If you want to use same version of python and environment on the command line, then you must activate the environment with

$ pyenv activate projectName-3.7.1

command.

For more command about pyenv-virtualenv you can look for reference sheet.