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?
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.
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.
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.
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.