[Python-Dev] Python program name

Antoine Pitrou solipsis at pitrou.net
Fri May 4 14:39:52 CEST 2012


On Fri, 4 May 2012 08:44:25 +0000 (UTC)
Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
> IIUC, the program name of the Python executable is set to whatever argv[0] is.
> Is there a reason for this, rather than using one of the various OS-specific
> APIs [1] for getting the name of the running executable? The reason I ask is
> that in a virtual environment (venv), the exe's path is the only thing you have
> to go on, and if you don't have that, you can't find the pyvenv.cfg file and
> hence the base Python from which the venv was created.
> 
> Of course argv[0] is normally set to the executable's path, but there's at least
> one test (in test_sys) where Python is spawned (via subprocess) with argv[0] set
> to "nonexistent". If run from a venv created from a source build, with no Python
> 3.3 installed, this test fails because the spawned Python can't locate the
> locale encoding, and bails.

If that's the only failing test, we can simply skip it when run from a
venv. A non-existent argv[0] is arguably a borderline case which you
should only encounter when e.g. embedding Python.

> I would prefer to use option 2 and change getpath.c / getpathp.c accordingly.
> Does anyone here see problems with that approach?

getpath.c is sufficiently byzantine that we don't want to complexify it
too much, IMHO.

Regards

Antoine.




More information about the Python-Dev mailing list