python ini文件读取失败无法启动应用_Python Windows启动程序没有读取`py.ini文件`

本文探讨了Python脚本中使用shebang行`#!/usr/bin/env python`时,如何搜索PATH路径中的Python解释器。通过实例展示了在不同shebang行设置下,如何影响`py.ini`文件的读取和Python版本的选择。同时,分析了Windows环境下,Python启动程序如何处理`py.ini`配置文件,并解释了在特定场景下不使用shebang行可能带来的影响。
摘要由CSDN通过智能技术生成

The /usr/bin/env form of shebang line has one further special property. Before looking for installed Python interpreters, this form will search the executable PATH for a Python executable. This corresponds to the behaviour of the Unix env program, which performs a PATH search.

奇怪的是,这个相同的功能似乎也适用于python3.4(或至少3.4.3版),尽管corresponding documentation page for Python 3.4没有提到它。我在这个答案的底部加入了这种行为的复制品。在

您的脚本似乎在顶部包含了shebang行#!/usr/bin/env python,而{}位于系统的PATH中的任何{}之前。你在评论中说It's important for this specific script not to have a shebang

但是那条线parse_shebang: found command: python

在启动程序的输出中,脚本必须有一个shebang行。在

我的系统上安装了Python2.7.10和Python3.4.3,在PATH上安装了2.7之前的3.4。我在C:\Users\Luke\AppData\Local中还有一个py.ini文件,其中包含以下内容:

^{2}$

以及一个test.py脚本,其中包含#!/usr/bin/env python

import sys; print(sys.version_info)

我已经将环境变量PYLAUNCH_DEBUG的值设置为1。使用py test.py运行此脚本,我得到以下输出:launcher build: 32bit

launcher executable: Console

Using local configuration file 'C:\Users\Luke\AppData\Local\py.ini'

File 'C:\WINDOWS\py.ini' non-existent

Called with command line: test.py

maybe_handle_shebang: read 60 bytes

maybe_handle_shebang: BOM not found, using UTF-8

parse_shebang: found command: python

searching PATH for python executable

Python on path: C:\Python34\python.EXE

located python on PATH: C:\Python34\python.EXE

run_child: about to run 'C:\Python34\python.EXE test.py'

sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)

child process exit code: 0

如果我将test.py脚本更改为#! python

import sys; print(sys.version_info)

(例如,从shebang行中删除/usr/bin/env)并重新运行py test.py,我得到以下结果:launcher build: 32bit

launcher executable: Console

Using local configuration file 'C:\Users\Luke\AppData\Local\py.ini'

File 'C:\WINDOWS\py.ini' non-existent

Called with command line: test.py

maybe_handle_shebang: read 48 bytes

maybe_handle_shebang: BOM not found, using UTF-8

parse_shebang: found command: python

locating Pythons in 64bit registry

locate_pythons_for_key: unable to open PythonCore key in HKCU

locate_pythons_for_key: unable to open PythonCore key in HKLM

locating Pythons in native registry

locate_pythons_for_key: unable to open PythonCore key in HKCU

locate_pythons_for_key: C:\Python27\python.exe is a 32bit executable

locate_pythons_for_key: C:\Python27\PCBuild\python.exe: The system cannot find the path specified.

locate_pythons_for_key: C:\Python27\PCBuild\amd64\python.exe: The system cannot find the path specified.

locate_pythons_for_key: C:\Python34\python.exe is a 32bit executable

locate_pythons_for_key: C:\Python34\PCBuild\python.exe: The system cannot find the path specified.

locate_pythons_for_key: C:\Python34\PCBuild\amd64\python.exe: The system cannot find the path specified.

found configured value 'python=2' in C:\Users\Luke\AppData\Local\py.ini

search for default Python found version 2.7 at 'C:\Python27\python.exe'

run_child: about to run 'C:\Python27\python.exe test.py'

sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

child process exit code: 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值