Pipenv with Conda?

user1592380 picture user1592380 · May 26, 2018 · Viewed 26k times · Source

I'm using Anaconda for my virtualenvs in win 10. I'm using git-bash .I've been reading about pipenv recently and decided to give it a try. I installed pipenv on my base conda python which is a version of python 2.7 using :

pip install pipenv

I can easily create a python environment using

conda create --name py3 python=3.6

but I tried:

$ pipenv install --three

which gave:

Warning: Python 3 was not found on your system…
You can specify specific versions of Python with:
  $ pipenv --python path\to\python
....\miniconda2\lib\site-packages\pipenv\_compat.py:86: ResourceWarning: Implicitly cleaning up <TemporaryDirectory 'c:\\users\\......\\appdata\\local\\temp\\pipenv-4_fzvq-requi
rements'>
  warnings.warn(warn_message, ResourceWarning)

Is it possible to use the 2 packages together?

Answer

anishpatel picture anishpatel · Jul 20, 2019

You can setup Pipenv to use Conda's Python executable and site packages directory (ref).

pipenv --python=$(conda run which python) --site-packages

You can check if you are indeed using your Conda environment in Pipenv:

pipenv run python
>>> import sys
>>> sys.executable, sys.path
# <directories under your Conda environment>

With NumPy installed through Conda, but not Pipenv, you can see that Pipenv will still find NumPy.

conda install numpy
pipenv run python
>>> import numpy as np
>>> np.__file__
# <path under your Conda environment>

When you install NumPy through Pipenv, it will shadow Conda's installation of the the package.

pipenv install numpy
pipenv run python
>>> import numpy as np
>>> np.__file__
# <path under your Pipenv environment>