[Python-ideas] Why is there no way to pass PYTHONPATH on the command line?

Gerald Britton gerald.britton at gmail.com
Wed Sep 19 21:02:45 CEST 2012

On 19 September 2012 17:36, Gerald Britton <gerald.britton at
gmail.com <http://mail.python.org/mailman/listinfo/python-ideas>>
>* FYI This works in Windows:*>**>* C:\Python26>set PYTHONPATH=c:\temp & python*>* Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]*>* on*>* win32*>* Type "help", "copyright", "credits" or "license" for more information.*>>>>* import sys*>>>>* sys.path*>* ['', 'c:\\temp', 'C:\\WINDOWS\\system32\\python26.zip',*>* 'C:\\Python26\\DLLs', 'C*>* :\\Python26\\lib', 'C:\\Python26\\lib\\plat-win',*>* 'C:\\Python26\\lib\\lib-tk', '*>* C:\\Python26', 'C:\\Python26\\lib\\site-packages',*>* 'C:\\Python26\\lib\\site-pack*>* ages\\wx-2.8-msw-unicode']*
> But it leaves PYTHONPATH set afterwards, and it overwrites any
> PYTHONPATH setting you may have had before.

Sure, but that's easy to remedy.  just add


to the end.  If you want to get fancy, save the current value in a
temporary variable and use it later to reset the value.

We're really dealing with a limitation of the Windows Shell.  Things
are somewhat better in PowerShell but it's still not like BASH.

Probably better to write a little script that saves the variable
PYTHONPATH, sets it as desired, calls Python, then resets it

Gerald Britton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120919/b34935dc/attachment.html>

More information about the Python-ideas mailing list