从 WSL 内部调用 Windows Python 的奇怪行为(Windows 上的 Bash)
Strange Behavior Calling Windows Python from Within WSL (Bash on Windows)
安装 WSL 后,我在我的 PC 上安装了两个 python,一个 Windows,一个在 WSL 中。开发人员声明 here 你 "can invoke Windows binaries directly from the WSL command line," 然而,当我尝试调用 python.exe 文件时,我得到以下奇怪的行为:
myprompt$ python.exe
1
2
print("test")
print "test"
File "<stdin>", line 4
print "test"
^
SyntaxError: Missing parentheses in call to 'print'
myprompt$
而如果交互式解释器是 运行ning,我会得到:
myprompt$ python.exe
>>>1
1
>>>2
2
print("test")
test
print "test"
File "<stdin>", line 1
print "test"
^
SyntaxError: Missing parentheses in call to 'print'
myprompt$
好像解释器是运行ning,但它没有给我提示,它在第一个错误时退出。有趣的是,如果我从 windows 命令提示符导航到同一目录并 运行 python.exe,一切正常。
P.S.: 我通过 Python 中的 sys.executable 命令找到了 Windows Python 安装的位置。
使用 -i
选项调出交互式解释器。所以 运行
python.exe -i
将从 WSL 以交互方式启动 windows 版本的 python。
安装 WSL 后,我在我的 PC 上安装了两个 python,一个 Windows,一个在 WSL 中。开发人员声明 here 你 "can invoke Windows binaries directly from the WSL command line," 然而,当我尝试调用 python.exe 文件时,我得到以下奇怪的行为:
myprompt$ python.exe
1
2
print("test")
print "test"
File "<stdin>", line 4
print "test"
^
SyntaxError: Missing parentheses in call to 'print'
myprompt$
而如果交互式解释器是 运行ning,我会得到:
myprompt$ python.exe
>>>1
1
>>>2
2
print("test")
test
print "test"
File "<stdin>", line 1
print "test"
^
SyntaxError: Missing parentheses in call to 'print'
myprompt$
好像解释器是运行ning,但它没有给我提示,它在第一个错误时退出。有趣的是,如果我从 windows 命令提示符导航到同一目录并 运行 python.exe,一切正常。
P.S.: 我通过 Python 中的 sys.executable 命令找到了 Windows Python 安装的位置。
使用 -i
选项调出交互式解释器。所以 运行
python.exe -i
将从 WSL 以交互方式启动 windows 版本的 python。