pipenv: only works in a installed folder?

Jeremy Chen picture Jeremy Chen · May 7, 2018 · Viewed 7.9k times · Source

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?

Answer

userzxcv picture userzxcv · Jul 2, 2019

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.