找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1417|回复: 2

[讨论] 从脚本运行时启动器不起作用?

1

主题

1

帖子

1

积分

贫民

积分
1
人工智能~曾 发表于 2021-7-9 12:17:16 | 显示全部楼层 |阅读模式
我电脑安装了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来运行!

问题出在哪里呢!


回复

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2021-7-15 22:13:32 来自手机 | 显示全部楼层
这个特性应该只在linuxF起作用
回复 支持 反对

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2021-7-15 22:13:59 来自手机 | 显示全部楼层
linux下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表