Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv: only works in a installed folder?

Pipenv seems to work only in the directory where the Pipfile lives. Maybe I'm trying to use it in a way it is not designed for.

For example, I installed a tool called "leo" (an editor) and no surprise that I will go to many folders and start pipenv run Leo and it will start to install another virtual environment. What's the workaround?

like image 502
Jeremy Chen Avatar asked May 06 '18 23:05

Jeremy Chen


People also ask

What is the difference between PIP install and Pipenv install?

While pip can install Python packages, Pipenv is recommended as it's a higher-level tool that simplifies dependency management for common use cases. This does a user installation to prevent breaking any system-wide packages.

Where is Pipenv installed?

pipenv stores all the virtual environments it creates in one place, which is a hidden directory in your home directory by default.

Which is better Pipenv or VENV?

TL;DR. pipenv creates isolated pip environments whereas pyenv+virtualenv creates virtualenvs that multiple projects can use.

Is VENV the same as Pipenv?

pipenv. pipenv- like venv - can be used to create virtual envelopes but additionally rolls-in package management and vulnerability checking functionality. Instead of using requirements. txt , pipenv delivers package management via Pipfile.


2 Answers

You can run pew from any directory:

# install pew using pip (not pipenv)
$ pip install pew
   ...

# get venv name
$ (cd <folder with Pipfile> && pipenv --venv)
<some path>/python-1234ABCD

# activate venv
$ pew workon python-1234ABCD

# run pipenv as usual
$ pipenv run leo

As far as I understand it, you can only execute commands like running a text editor with pipenv if you are currently already running a virtual environment with pipenv. If not, it will make a new virtual env in the current directory and then run the command in it.

The result of pipenv --help says, for the run command:

run Spawns a command installed into the virtualenv.

like image 194
userzxcv Avatar answered Sep 28 '22 13:09

userzxcv


At the directory where Pipfile resides, do

pipenv --venv

This will show the path where the virtual env is located. Copy that path, such as /Users/yourname/.local/share/virtualenvs/yourproject-8XhejQjj, and at any other folder you can activate the venv with source, e.g.:

source /Users/yourname/.local/share/virtualenvs/yourproject-8XhejQjj/bin/activate

This is covered by Ken Reitz's 2018 PyData talk.

like image 31
ji.xu Avatar answered Sep 28 '22 11:09

ji.xu