Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows上使用多版本Python的PyScripter_Python_Windows_Python 2.7_Operating System_Pyscripter - Fatal编程技术网

在Windows上使用多版本Python的PyScripter

在Windows上使用多版本Python的PyScripter,python,windows,python-2.7,operating-system,pyscripter,Python,Windows,Python 2.7,Operating System,Pyscripter,我最近在我的计算机(Windows7,32位)上安装了Python 3.3和Python 2.7。Python3.3提供了在.py文件顶部添加“shebang行”的可能性,因此当您执行它们时,它可以选择使用哪个Python版本。由于Pyscripter无法识别这个“shebang行”,我编写了一个程序,读取.py文件的第一行,然后在Pyscripter中用相应的参数打开它。 看起来是这样的: #!/usr/bin/env python2.7 from sys import argv from o

我最近在我的计算机(Windows7,32位)上安装了Python 3.3和Python 2.7。Python3.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编译了该程序,并选择is作为.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的程序是Python2.7,因为我没有py2exe for Python3。

尝试使用模块而不是
system()
来启动
PyScripter.exe
子进程。Popen()
工作正常,谢谢