Not very sure if this is an expected behavior, but from a usage perspective this appears to be a bug:
pipenv install <package_name>
is creating a new virtualenv even though the virtualenv is activated using pipenv shell
.
if we are not in the same directory where Pipfile
is located.
$ python -V
== 3.6.3$ pipenv --version
== version 8.3.1If 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
.
A new Pipfile gets created, even if in the same activated virtualenv but in a different directory.
$ 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
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.
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:
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):
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.