1

我最近在我的计算机(Windows 7、32 位)上安装了 Python 3.3 和 Python 2.7。Python 3.3 让您可以在 .py 文件的顶部添加“shebang 行”,因此当您执行它们时,它可以选择要使用的 Python 版本。由于 Pyscripter 无法识别这个“shebang 行”,我编写了一个程序,它读取 .py 文件的第一行,然后在 Pyscripter 中使用相应的参数打开它。它看起来像这样:

#!/usr/bin/env python2.7
from sys import argv
from os import system
if len(argv)>1:
    file = open(argv[1])
    shebang=file.readline()
    if shebang.split()[1] in {'python2','python2.7'}:
        system(r'C:\Python27\PyScripter.exe --python27 "'+argv[1]+'"')
    elif shebang.split()[1] in {'python3','python3.3'}:
        system(r'C:\Python33\PyScripter.exe --python33 "'+argv[1]+'"')
else:
    system(r'C:\Python27\PyScripter.exe --python27')
file.close()
exit()

然后我使用 py2exe 编译了程序,并选择了 .py 文件的标准操作。当我现在打开一个 .py 文件时,PyScripter 使用正确版本的 python 打开文件,但是当我尝试保存文件时它说:

Error saving file: "C:\Users\...\Python\example.py".
Error: Cannot create file "C:\Users\...\Python\example.py". The process cannot acces the file because it is being used by another process

用于打开 PyScripter 的编译程序仍在运行,但即使我杀死它,它仍然会带来该消息。程序打开的 cmd.exe 窗口也会发生同样的情况。如果我尝试在 Windows 资源管理器中删除/重命名/移动文件,它说我不能这样做,因为 PyScripter.exe 当前正在使用该文件。有谁知道如何解决这个问题?

打开 PyScripter 的程序是 Python 2.7,因为我没有用于 Python 3 的 py2exe。

4

0 回答 0