Search code examples
pythonmacosshellcommand-linepipenv

How to use pipenv in Python shell script?


I needed a module for a shell script I've written in Python, so I used pipenv to install it. I can run the command fine using:

~$ pipenv run python3 foo

Now, if I want to just run ~$ foo on the command line (fish shell on MacOS, homebrew installed), how do I invoke the pipenv environment in the shebang of my Python script? Or is there a better way?


Solution

  • With pipenv-shebang you can run your script with

    pipenv-shebang PATH/SCRIPT
    

    or you could insert the shebang

    #!/usr/bin/env pipenv-shebang
    

    to run it with just PATH/SCRIPT.