python.exe和pythonw.exe print(os.environ)结果之间的PATH变量的差异

时间:2016-02-08 20:21:29

标签: python python-3.x

我有一个奇怪的问题:

执行此操作时:

print(os.environ) 

在python.exe中,我看到一件事,在IDLE(pythonw.exe)中,为什么?

这可能是某种缓存还是什么?

PS我的系统:Windows 7 x64和Python 3.5.1 x32

为什么你把它标记为重复,我没有找到这类问题的答案。我读到了python.exe和pythonw.exe的区别,但我不明白为什么PATH变量是不同的。

这是干涉:

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网络适配器\驱动程序; C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files \ Lenovo \ Bluetooth软件\; 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)管理引擎组件\ DAL; C:\ Program Files(x86)\ Intel \ Intel(R)管理引擎组件\ 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 File s(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网络适配器\驱动程序; C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files \ Lenovo \ Bluetooth软件\; 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)管理引擎组件\ DAL; C:\ Program Files(x86)\ Intel \ Intel(R)管理引擎组件\ 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 \ < / p>

您是否在python.exe结果中看到了nodejs路径,而在pythonw.exe中没有看到它?我删除了所有pyc文件但没有帮助

1 个答案:

答案 0 :(得分:1)

PATH环境变量的值与difference between python.exe and pythonw.exe几乎没有关系。关于PATH或一般的环境变量,您需要了解的是它们通常是从调用进程继承的。

因此,当您从命令行调用python.exe时,该进程将继承命令行具有的PATH值。如果使用某个快捷方式打开IDLE,则它将从Windows继承该值。

每个进程都可以随心所欲地处理环境变量;因此影响他们开始的过程。例如:

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'

就像我创建了一个新的环境变量FOO,它自动传递给我开始的进程(Python 3),可以在那里访问它。

这同样适用于PATH环境变量。如果您在那里看到差异,可能不是因为您的可执行文件不同,而是因为调用进程可能以不同的方式影响它。