How do I properly setup pipenv in PyCharm?

Question:

I need krakenex in a project, so I import it with

import krakenex

I have one version of krakenex in

/Users/x/Library/Python/3.6/lib/python/site-packages

. When I execute the script and

print(krakenex)

it shows me the path mentioned above.

In the future, I want to use the modules from the packages I installed with e.g.

pipenv install krakenex

with priority.

How do I manage to do that? Is it sufficient to add the path of the virtual environment to the sys path, or is there a more elegant way?

Asked By: Chris Jung

||

Answers:

You should be pointing your Project Interpreter to the virtualenv python bin. So in PyCharm File->Settings->Project: ProjectName->Project Interpreter, then a windows showing the Project Interpreter should be displayed.

Project Interpreter

Next to the top dropdown is a gear and your going to want to Add Local and navigate to the virtualenvs python bin. Something like virtualenvs/virtualenv_name/bin/python. Then your project should be pointing to the right place.

Answered By: ForFunAndProfit

To add more clarification on how to setup PyCharm with pipenv for now:

  1. Execute in your project directory

    pipenv –venv

Save the output, you’ll reference this path later

  1. In PyCharm, Open Project Settings, and then select project interpreter
    Preferences > Project Interpreter

  2. Click Add a Python Interpreter > System Interpreter > Select Python Interpreter and paste the output from the first command, appending /bin/python onto the end.
    enter image description here

Note that you will need to use the command line to install any packages since PyCharm currently doesn’t support pipenv in their package management tools. However, I haven’t had a problem with this method.

Answered By: Lawrence Coleman

PyCharm natively supports pipenv since version 2018.2. PyCharm 2018.2 will automatically create a pipenv when you open a project with a Pipfile, and makes it easy to create new projects with pipenvs.

For existing projects

As previously stated, for existing projects with a Pipfile, when you open a Python file, PyCharm will ask you if you want to install the dependencies from the Pipfile.lock.

pipenv for existing projects

For new projects

For a new project, you can use the project interpreter panel to create a Pipenv based project interpreter.

enter image description here

Answered By: lmiguelvargasf

Make sure to update PyCharm. I updated to 2018.3.

Export path for pipenv: $ export PATH="$PATH:Users/{user_name}/.local/bin"

PyCharm will then automatically detect pipenv under new environment using dropbox. Reference image here and see full blog post here.

Answered By: Adnan Murtaza
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.