1

I have a Python app that I use locally that needs to be launched via pipenv run python3 appname.py in order to load virtual environment with installed dependencies. This is all on macOS.

What I want to achieve is to be able to run this app from anywhere with $ appname [args].

So what I did was:

  • add #!/usr/bin/env pipenv run python3 to appname.py;
  • make that file executable with chmod +x appname.py;
  • make symlink with ln -s /path/to/appname.py ~/.bin/appname;
  • put ~/.bin on my $PATH.

Now when I launch $ appname, pipenv creates a new virtual environment in the ~/.bin folder and complains about missing dependencies, all instead of following through into the actual location of the script.

Is there a way to overcome this? Or maybe a better way to achieve what I want?

CBlew
  • 691
  • 7
  • 20
  • Note that `#!/usr/bin/env pipenv run python3` will run `env "pipenv run python3"` meaning those arguments will be passed a single string to `/usr/bin/env`. You can only use _a single_ argument in the shebang line – hek2mgl Jan 12 '19 at 18:00
  • See https://stackoverflow.com/a/57171701/52817 – laktak Aug 02 '19 at 20:08

1 Answers1

0

For my purposes a more sensible thing to do was freezing my code by packaging it (along with all dependencies) into an executable with pyinstaller.

What I did was:

  1. Installed pyinstaller as dev dependency with pipenv install --dev pyinstaller;
  2. Launched pipenv shell in the project directory;
  3. Packaged the app with pyinstaller --onefile appname.py;
  4. Moved the resulting self-containing [project path]/dist/appname executable into my ~/.bin directory.

There were some unrelated issues to overcome, but otherwise worked perfectly for me.

CBlew
  • 691
  • 7
  • 20