Reputation: 27186
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 ?
Upvotes: 15
Views: 11415
Reputation: 396
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.)
Upvotes: 36
Reputation: 149
pipenv is a wrapper for virtualenv which keeps the virtualenv-files in some folder in your home directory. I found them in /home/MYUSERNAME/.local/share/virtualenvs
.
So i wrote a small_script.sh
:
#!/bin/bash
source /home/MYUSERNAME/.local/share/virtualenvs/MYCODE-9as8Da87/bin/activate
python /PATH/TO/MY/CODE/foo.py localfile.conf
deactivate
It activates the virtualenv for itself, then runs your python code in your local directory and finally deactivates the virtualenv.
You can replace localfile.conf
by $@
which allows you to run ./small_script.sh localfile.conf
.
Upvotes: 5