39

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?

2
  • You need to have python3 on your path or explicitly state it.
    – AChampion
    May 26, 2018 at 19:29
  • Ok , I read that too, but my anaconda has a python27 in the base path not python3. Is there a way to add python3 there? May 26, 2018 at 19:42

3 Answers 3

40

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>
1
  • How to undo pipenv --python=$(conda run which python) --site-packages? @anishpatel
    – Ali Husham
    Nov 26, 2021 at 7:27
19

You can install pipenv within a conda environment initialized with python 3.

$ conda create -n pipenv-test python=3
$ source activate pipenv-test
(pipenv-test)$ pipenv install --python=/home/.../miniconda3/envs/pipenv-test/bin/python
Creating a virtualenv for this project…
Using /home/.../miniconda3/envs/pipenv-test/bin/python (3.6.5) to create virtualenv…
⠋Already using interpreter /home/.../miniconda3/envs/pipenv-test/bin/python
Using base prefix '/home/.../miniconda3/envs/pipenv-test'
New python executable in /home/.../.local/share/virtualenvs/wispy-j1ojliDY/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/.../.local/share/virtualenvs/wispy-j1ojliDY
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (ca72e7)!
Installing dependencies from Pipfile.lock (ca72e7)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run the following:
 $ pipenv shell

This seems to work for me but I haven't tested it extensively. Also, my base conda python is 3.6 and I'm using Ubuntu 16.04. I'm curious to hear whether this still gives you trouble.

7
  • I'm trying your commands in git-bash . in the pipenv-test conda env do you need to run pip install pipenv before '$ pipenv install ..miniconda\envs\pipenv-test ? ' Jun 23, 2018 at 17:34
  • I did 'conda install pip' but it turns out it was installed by default. You can check if it's there with 'conda list'. But that may be a difference between linux and the window anaconda git bash.
    – kde8
    Jun 23, 2018 at 18:28
  • 5
    How do your steps show how "you can install pipenv within a conda environment initialized with Python 3"? That seems to imply running something like pip install pipenv within the environment, but your instructions assume pipenv is already available after activation.
    – rob3c
    Sep 20, 2018 at 18:48
  • 2
    Sorry for the slow reply. @rob3c you are correct, I forgot to include that in my original answer. I did in fact do pip install pipenv within the conda environment first.
    – kde8
    Nov 6, 2018 at 17:02
  • 3
    Its not a good thing to use pip with conda. anaconda.com/using-pip-in-a-conda-environment Jun 26, 2019 at 5:39
-3

without the '$'

pipenv install --three
1
  • 10
    I believe the $ is meant as the terminal entry, not part of the command...
    – Tomerikoo
    Nov 8, 2021 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.