1

I installed pip by downloading virtualenv, and creating a bootstrap virtualenv, as described in this answer.

Now I want to try out pipenv, so I used my bootstrap virtualenv to create a new virtualenv and then ran pip install pipenv. Now I can use pipenv, but it sees that it's already running in a virtualenv and doesn't create a new one.

How can I get pipenv to create a new virtualenv so I can have separate virtualenvs for each project? I tried pipenv install -h, but none of the options look promising.

Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • To separate environments, you just need to run `pipenv` in other project's directory. Be sure to deactivate your current virtualenv first. – Sraw Feb 08 '18 at 08:26
  • To clarify, @Sraw, `pipenv` is only installed in a virtualenv. I don't want to install it in my system Python. I can't deactivate my current virtualenv, because that's where `pipenv` is installed. – Don Kirkby Feb 08 '18 at 19:35

3 Answers3

6

The current documentation makes it sound like you can set the environment variable PIPENV_IGNORE_VIRTUALENVS to avoid reusing an already activated virtualenv:

source ~/some/virtualenv/location/bin/activate
PIPENV_IGNORE_VIRTUALENVS=1 pipenv install

I have to admit that I haven't tried this, though.

karlson
  • 5,325
  • 3
  • 30
  • 62
5

If you're in a new project directory, these commands create a new virtualenv using pipenv:

Create a new virtualenv with python 2:

pipenv --two

Create a new virtualenv with python 3:

pipenv --three

Create a new virtualenv with an arbitrary python version:

pipenv --python 3.6.4
philngo
  • 913
  • 7
  • 12
  • That doesn't work for me. I think it's because I've installed `pipenv` in a virtualenv. It says it's reusing that virtualenv instead of creating a new one. My question is whether I can tell it to create a new one anyway. – Don Kirkby Feb 11 '18 at 04:37
  • I see what you’re getting at. If you’d like to keep your installation of pipenv separate from system dependencies, but use it to create new virtualenvs, you might try using the fancy installation method in the docs. https://docs.pipenv.org/install/#fancy-installation-of-pipenv. The suggestion is to install pipenv with pipsi, which puts it into an isolated virtualenv but makes it available as a command globally. – philngo Feb 11 '18 at 06:45
  • Another option you could use is `pipenv install --system`, which would tell pipenv to use the _current_ virtualenv (still not creating a separate one), but that would likely require installing pipenv into each new project virtualenv you create. It would, however, let you keep separated virtualenvs for each project. Maybe a trade-off you're willing to make. – philngo Feb 11 '18 at 06:59
0

It looks like pipenv has gotten smarter about this situation. Here's what worked for me. First, I installed a bootstrap environment following virtualenv's installation documentation to use it locally from source. That way, I don't need to touch the system Python, and I can install pipenv in the bootstrap environment:

$ curl --location --output virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/16.1.0
$ tar -xzf virtualenv.tar.gz
$ python pypa-virtualenv-4ad2742/src/virtualenv.py vbootstrap
$ rm -r virtualenv.tar.gz pypa-virtualenv-4ad2742/
$ vbootstrap/bin/pip install pipenv

Then I created a new project folder, and used pipenv to install numpy:

$ mkdir my_project
$ cd my_project
$ ../vbootstrap/bin/pipenv install numpy
Creating a virtualenv for this project...
Pipfile: /home/vagrant/my_project/Pipfile
Using /home/vagrant/vbootstrap/bin/python (2.7.15rc1) to create virtualenv...
✔ Complete 
Already using interpreter /home/vagrant/vbootstrap/bin/python
Using real prefix '/usr'
New python executable in /home/vagrant/.local/share/virtualenvs/my_project-KmT425B_/bin/python
Installing setuptools, pip, wheel...
done.
Virtualenv location: /home/vagrant/.local/share/virtualenvs/my_project-KmT425B_
Creating a Pipfile for this project...
Installing numpy...
Adding numpy to Pipfile's [packages]...
✔ Installation Succeeded 
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
✔ Success! 
Updated Pipfile.lock (57a39c)!
Installing dependencies from Pipfile.lock (57a39c)...
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

To make it easier to use, I created a symbolic link:

$ ln -s ~/vbootstrap/bin/pipenv ~/pipenv
$ ~/pipenv shell
Launching subshell in virtual environment...
vagrant@vagrant:~/my_project$  . /home/vagrant/.local/share/virtualenvs/my_project-KmT425B_/bin/activate
(my_project) $
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286