Don Kirkby
Don Kirkby

Reputation: 56590

Force pipenv to create a new virtualenv

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.

Upvotes: 1

Views: 15512

Answers (4)

Hari
Hari

Reputation: 69

first run

pipenv shell

then after run

pipenv --venv

Upvotes: 0

karlson
karlson

Reputation: 5433

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.

Upvotes: 6

Don Kirkby
Don Kirkby

Reputation: 56590

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) $

Upvotes: 0

philngo
philngo

Reputation: 931

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

Upvotes: 4

Related Questions