How do I properly setup pipenv in PyCharm?
Solution 1
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.
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.
Solution 2
To add more clarification on how to setup PyCharm with pipenv for now:
-
Execute in your project directory
pipenv --venv
Save the output, you'll reference this path later
In PyCharm, Open Project Settings, and then select project interpreter
Click Add a Python Interpreter > System Interpreter > Select Python Interpreter and paste the output from the first command, appending /bin/python onto the end.
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.
Solution 3
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
.
For new projects
For a new project, you can use the project interpreter panel to create a Pipenv
based project interpreter.
Solution 4
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.
Related videos on Youtube
Comments
-
Chris Jung over 3 years
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?
-
Iulian Onofrei over 5 yearsConsider marking this answer as the solution.
-
PolarBear10 about 5 yearsNot the case anymore, please check stackoverflow.com/questions/55306431/…
-
-
Vibin over 6 yearsThis works great! Is there also a way to point pycharm to pipenv or pip so that one can install new modules via the pycharm fix action?
-
Almog Cohen about 6 years@Vibin PyCharm would use the
pip
that is linked to the project interpreter. The answer above should work for you installing things from within PyCharm. -
ramazan polat about 6 years@AlmogCohen unfortunately PyCharm doesn't use pipenv for installing new modules, even if the project interpreter is linked to pipenv environment.
-
Jonathan Stray almost 6 yearsDid this, and all my Run configurations no longer work :/ Had to edit the interpreter in each config to point to the virtualenv
-
Almog Cohen almost 6 years@RamazanPolat PyCharm should add internal support for
pipenv
-
ForFunAndProfit almost 6 years@AlmogCohen They are adding it in the next release or if you felt like using an early access version it has it now. confluence.jetbrains.com/display/PYH/…
-
Almog Cohen almost 6 years@ForFunAndProfit you are awesome. They are awesome!
-
Toby over 5 yearsThe support for pipenv in pycharm is ridiculous as of 2018.3. PyCharm doesn't even check if there already is an existing virtualenv, it just creates a new one (it should check with pipenv --venv). Furthermore pipenv respects the WORKON_HOME env variable, which cannot be set in PyCharm.
-
lmiguelvargasf over 5 years@Toby, I think now it checks. I am using 2018.3.1, and it is actually looking for the virtual environment that I previously created using
pipenv
. -
Toby over 5 years@lmiguelvargasf Nice! I also found out in the meantime that there is a difference between 'create new project' and 'open'. The latter does check in a default location. I symlinked that to where my WORKON_HOME points, and that worked.
-
PolarBear10 about 5 years@ForFunAndProfit please check stackoverflow.com/questions/55306431/…
-
PolarBear10 about 5 years@Imiguelvargasf Not the case anymore, please check stackoverflow.com/questions/55306431/…
-
Jon Cage about 5 yearsThis didn't work for me in the 2017 edition. Upgrading to 2019 resolved it.
-
Chase Denecke almost 2 yearsOn MacOS, go to PyCharm --> preferences --> Project: [project name] instead of file --> settings --> project