我电脑安装了python3.4和python3.9,我写一个程序which.py来测试启动器的作用:
#! python3.4-64
import sys
print('python 版本:',sys.version)
input()
当我从命令行用py命令来启动时,没有问题:
C:\Users\Administrator>py D:\code\run\which.py
python 版本: 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
但当我双击which.py运行,或直接在命令行输入文件运行,却打印出“python 版本: 3.9.0”:
C:\Users\Administrator>D:\code\run\which.py
python 版本: 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
这与python的官方文档所说的并不相同,官方文档这样说:
3.8.1.4. From file associati**The launcher should have been associated with Python files (i.e. .py, .pyw, .pyc files) when it was installed. This means that when you double-click on one of these files from Windows explorer the launcher will be used, and therefore you can use the same facilities described above to have the script specify the version which should be used.
当安装时启动器应该已经与python文件关联,这意味着在windows资源管理器中双击python文件会使用启动器,因此您可以使用上述相同的工具让脚本来指定使用的python版本。
也就是说,可以用 #! 来指定python版本!
可实际情况是,当双击运行时,它并没有按#! python3.4-64行指定的python版本来运行,而是用python3.9.0来运行!
问题出在哪里呢!
|