简体   繁体   English

从bash终端运行Visual Python脚本

[英]Run Visual Python script from bash terminal

I am trying to run the example programs that come with Visual Python ("VPython") like bounce.py , orbit.py , etc through bash. 我正在尝试通过bash运行Visual Python(“ VPython”) bounce.py的示例程序,例如bounce.pyorbit.py等。

When I'm in the folder which contains these examples (C:\\Python27\\Lib\\site-packages\\visual\\examples) , I can right-click on any of the examples and choose "open with" and then select "python.exe" from the list of given programs. 当我进入包含以下示例的文件夹(C:\\ Python27 \\ Lib \\ site-packages \\ visual \\ examples)时 ,可以右键单击任何示例,然后选择“打开方式”,然后选择“ python”。 exe”。 This method is able to run the programs just fine and it generates the visual representation of a ball bouncing in a room, orbiting balls, etc. 这种方法能够很好地运行程序,并且可以生成房间内弹跳的球,环绕的球等的视觉表示。

On the other hand, when I use bash to navigate to this folder and then try to run python bounce.py , I get the error message: 另一方面,当我使用bash导航到此文件夹,然后尝试运行python bounce.py ,出现错误消息:

Traceback (most recent call last): File "bounce.py", line 1, in from visual import * ImportError: No module named visual 追溯(最近一次通话):文件“ bounce.py”,行1,来自可视导入* ImportError:没有名为visual的模块

I was under the impression that calling python bounce.py was effectively the same as opening the file with the python executable but the behavior is different. 我的印象是,调用python bounce.py实际上与使用python可执行文件打开文件相同,但是行为有所不同。 I'm not sure why the "open with python.exe" method would allow the example to find the visual module but opening the example through bash is unable to find the same module. 我不确定为什么“使用python.exe打开”方法将允许示例查找可视模块,但通过bash打开示例无法找到相同的模块。 Any advice or help would be appreciated. 任何建议或帮助,将不胜感激。

(Side note, I am running Bash on Ubuntu on Windows through the new beta https://msdn.microsoft.com/en-us/commandline/wsl/about ) (附带说明,我正在Windows上通过新的beta版https://msdn.microsoft.com/en-us/commandline/wsl/about在Ubuntu上运行Bash)

The Linux environment (Bash on Windows) includes a builtin python, which does not have the package visual . Linux环境(Windows上的Bash)包括一个内置的python,它没有软件包visual

If you double-click the file, right-click and then open with python.exe , or execute the script via cmd or powershell , it will use the Python installed on the Windows machine. 如果双击文件,单击鼠标右键,然后open with python.exe ,或通过cmdpowershell执行脚本,它将使用Windows计算机上安装的Python。 If you execute the script in bash , it will use the Python in Linux subsystem. 如果在bash执行脚本,它将在Linux子系统中使用Python。 That's it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM