[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:13:39 CEST 2012

BTW, this works:

PS C:\Python26> powershell {Set-Item -Path env:PYTHONPATH -value C:\temp;
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\\p
lat-win', 'c:\\python26\\lib\\lib-tk', 'c:\\python26',
'c:\\python26\\lib\\site-packages', 'c:\\python26\\lib\\site-pack
>>> ^Z

PS C:\Python26> ls env:PYTHONPATH
Get-ChildItem : Cannot find path 'PYTHONPATH' because it does not exist.
At line:1 char:3
+ ls <<<<  env:PYTHONPATH
    + CategoryInfo          : ObjectNotFound: (PYTHONPATH:String)
[Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId :

PS C:\Python26>

On Wed, Sep 19, 2012 at 3:02 PM, Gerald Britton <gerald.britton at gmail.com>wrote:

> On 19 September 2012 17:36, Gerald Britton <gerald.britton at gmail.com <http://mail.python.org/mailman/listinfo/python-ideas>> wrote:
> >* 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
> & set *PYTHONPATH=*
> 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 afterwards.
> --
> Gerald Britton

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

More information about the Python-ideas mailing list