Portable executable on OSX

Chris Angelico rosuav at gmail.com
Thu Oct 20 17:53:51 EDT 2022


On Fri, 21 Oct 2022 at 08:50, Thomas Passin <list1 at tompassin.net> wrote:
>
> "Portable executable" usually means that the program resides on
> removable media, like a USB stick.  You can go to a computer, plug the
> stick in, and run the program.  If it's Python, then the installation on
> the removable medium needs to set up all the paths and directories
> correctly before actually running Python. That would typically be done
> with batch files setting paths and environmental variables.
>
> I got this working for Python on Windows some years ago.  Here is the
> setup batch file I used - it gets executed when the user types "pyth37":
>
> @echo off
> setlocal
> : Find effective drive for this file.
> set ed=%~d0
> path %ed%\python37\Scripts;%ed%\python37;%PATH%
> set PYTHONUSERBASE=%ed%\user\python
> set HOME=%ed%\user\python
> call python %*
> endlocal
>
> It might need to be be more complex on MacOS, but it gives you the idea.
>   The odd-looking line "set ed=%~d0" is a Windows-specific way to get
> the drive of the command file being run.
>

Basic idea looks sound. Might actually be _easier_ on OSX, since it's
Unix-like and you should be able to depend on /bin/bash. The notation
`dirname $0` should give you the path to the current script, from
which everything else can be calculated.

(Caveat: Never actually done this on a Mac, and only did cursory web
searching to check that it wasn't a ridiculous idea.)

ChrisA


More information about the Python-list mailing list