Incomplete sys.path with embeddable python (Windows)!?

Thomas Passin list1 at tompassin.net
Sat Apr 22 18:17:59 EDT 2023


On 4/22/2023 5:45 PM, Ralf M. wrote:
> Am 22.04.2023 um 03:27 schrieb Greg Ewing via Python-list:
>> How are you invoking your script? Presumably you have some code
>> in your embedding application that takes a script path and runs
>> it. Instead of putting the code to update sys.path into every
>> script, the embedding application could do it before running
>> the script.
>>
> In principle a good idea, but I don't know how to do that:
> The script is currently invoked by a .cmd file, but that may change to a 
> shortcut (.lnk). This is what the embeddable package documentation calls 
> "Python Application - simple approach".
> To update sys.path on start up I would need to do something like
>    C:\path\to\python.exe --add-path C:\s-path C:\s-path\script.py
> but I couldn't find an option like --add-path.

You can get the .cmd file's path and put it into an environmental 
variable (or as a command line argument).  If you haven't encountered 
that trick of Windows batch file procesing, here it is:

%~dp0 (returns the directory a batch file is running from)



More information about the Python-list mailing list