Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a Python pipenv from another directory?

Tags:

python

pipenv

I have a project for which I'd now like to use pipenv.

I want to symlink this from my main bin directory, so I can run it from another directory (where it interacts with local files) but nevertheless run it in the pipenv with the appropriately installed files.

Can I do something like

pipenv run python /PATH/TO/MY/CODE/foo.py localfile.conf

Or is that not going to pick up the pipenv defined in /PATH/TO/MY/CODE/Pipenv ?

like image 810
interstar Avatar asked Nov 06 '18 18:11

interstar


People also ask

How do I run a pipenv in Python?

You generally don't need to know the path to the virtual environment Pipenv creates. To activate the environment, just navigate to your project directory and use pipenv shell to launch a new shell session or use pipenv run <command> to run a command directly.

How do I add a path to pipenv?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), navigate to Tools | Python Integrated Tools, and type the target path in the Path ot Pipenv executable field. After the preparation steps are done, you can use pipenv to create a virtual environment for new or existing projects.

How do I run a pipenv shell in Windows?

How do I install Pipenv on Windows 10? Install pipenv by running the following command: $ pip install –user pipenv. For your convenience, you might add the user base's binary directory to your PATH environmental variable.

Where is the pipenv executable?

Discover the proper executable path as described in the pipenv installation procedure and enter the target string in the Pipenv executable field, for example: C:\Users\jetbrains\AppData\Roaming\Python\Python37\Scripts\pipenv.exe (Windows) or /Users/jetbrains/. local/bin/pipenv (macOS).


1 Answers

Not sure if this was relevant with the version of pipenv you used in 2018, but as of current versions you can use the PIPENV_PIPFILE environment variable. You will end up with a wrapper shell script that looks something like:

export PIPENV_PIPFILE=/my/project/dir/Pipfile
exec pipenv run command ...

(Answering even though I'm half a year late because this was the first relevant search result, so I can find it again next time.)

like image 179
Mook Avatar answered Sep 21 '22 12:09

Mook