pipenv is not respecting the current activated virtualenv and creating new env

Created on 2 Nov 2017  路  3Comments  路  Source: pypa/pipenv

Not very sure if this is an expected behavior, but from a usage perspective this appears to be a bug:

Issue:

pipenv install <package_name> is creating a new virtualenv even though the virtualenv is activated using pipenv shell.

When does it occur:

if we are not in the same directory where Pipfile is located.

Describe your environment

  1. OS Type: Linux (Ubuntu 16.04)
  2. Python version: $ python -V== 3.6.3
  3. Pipenv version: $ pipenv --version == version 8.3.1

Expected result

If we are in an activated virtualenv shell, (irrespective of the pwd) pipenv install should respect it and correctly update the Pipfile and should not create a new Pipfile.

Actual result

A new Pipfile gets created, even if in the same activated virtualenv but in a different directory.

Steps to replicate

$ mkdir -p testproject/app
$ cd  testproject/app
$ pipenv install flask
$ pipenv shell # environment gets activated here
$ <my_new_environment>$  cd ..  # Now we are inside testproject
$ pipenv install requests
$ New Pipfile gets created here

Most helpful comment

@erinxocon And herein lies the problem: users expect pipenv to be a replacement for pip.

@kennethreitz said it himself on the pipenv homepage:

You no longer need to use pip and virtualenv separately. They work together.

pipenv is supposed to not only create the virtualenv, as you said, but also manage it. Again, it's mentioned explicitly on the homepage (emphasis mine):

It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages.

In the old days, when we used virtualenv and pip separately, we could navigate to any directory and pip install, and the package would be correctly installed into the virtualenv, the fact that pipenv doesn't do that _while a pipenv-managed virtualenv is activated_ breaks user expectation.

All 3 comments

Hi @ansrivas! This is not the intended flow of pipenv. Pipenv will use a virtual environment if it finds itself in one initially but not on all subsequent calls. You'd have a rather hairy nest of virtualenvs! If you navigate to a folder that is outside of the project, pipenv will create a new pipfile. If you just want to install some packages outside of the folder, but inside the virutalenvironment you activated in the subshell you could do pipenv shell and then pip install requests. Pipenv can be used to create a virtualenv for your project, but it in it of itself isn't a virtualenv manager, it's a project manager.

@erinxocon And herein lies the problem: users expect pipenv to be a replacement for pip.

@kennethreitz said it himself on the pipenv homepage:

You no longer need to use pip and virtualenv separately. They work together.

pipenv is supposed to not only create the virtualenv, as you said, but also manage it. Again, it's mentioned explicitly on the homepage (emphasis mine):

It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages.

In the old days, when we used virtualenv and pip separately, we could navigate to any directory and pip install, and the package would be correctly installed into the virtualenv, the fact that pipenv doesn't do that _while a pipenv-managed virtualenv is activated_ breaks user expectation.

I'm agreeing with @ksze on this.

There's an expectation that pipenv should be managing the active virtualenv.

Along similar lines... I should be able to use the -r to install an external Pipfile or Pipenv.lock into the current virtualenv, and not create another.

Was this page helpful?
0 / 5 - 0 ratings