Xion
Xion

Reputation: 41

Difference of PATH variable between python.exe and pythonw.exe print(os.environ) result

I have strange problem:

When I execute this:

print(os.environ) 

in python.exe, I see one thing and in IDLE (pythonw.exe) another, why?

May be this is some kind of cache or what?

PS my system: Windows 7 x64 and Python 3.5.1 x32


Why you mark it duplicate, I didnt found answer for this type of issue. I read about difference of python.exe and pythonw.exe, but I don't understand why PATH variable is differents.


Here is defference:

python.exe:

C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter\Driver;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files (x86)\nodejs\;C:\Users\someusername\AppData\Local\Programs\ Python\Python35-32\Scripts\;C:\Users\someusername\AppData\Local\Programs\Python\Python35-32\;C:\Program Files (x86)\nodejs\;C:\Users\someusername\AppData\Roaming\npm

pythonw.exe:

C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter\Driver;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Users\someusername\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\someusername\AppData\Local\Programs\Python\Python35-32\

Do you see nodejs path in python.exe result, and not of it in pythonw.exe? I deleted all pyc file but that not helps

Upvotes: 0

Views: 1410

Answers (1)

poke
poke

Reputation: 387527

The value of the PATH environment variable has very little to do with the difference between python.exe and pythonw.exe. What you need to know about PATH, or environment variables in general, is that they are usually inherited from the calling process.

So when you call python.exe from the command line, then that process will inherit the value of PATH that the command line had. If you open IDLE using some shortcut, then it will inherit the value from Windows.

Every process can mess with the environment variables as much as they like; and as such affect processes they start. For example:

C:\>set FOO=Hello world
C:\>py -3
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['FOO']
'Hello world'
>>> ^Z

C:\>set FOO=Hello world foo bar baz
C:\>py -3
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['FOO']
'Hello world foo bar baz'

And just like that I created a new environment variable FOO which was passed automatically to the process I was starting (Python 3), which could access it there.

The same really applies to the PATH environment variable. If you are seeing differences there, it’s likely not because your executable is different, but more because the calling process may have affected it in a different way.

Upvotes: 1

Related Questions