简体   繁体   English

来自cmd的Python IDLE

[英]Python IDLE from cmd

How to open my .py script from anywhere on my pc directly into python idle form command prompt? 如何从我的电脑上的任何地方直接打开我的.py脚本到python空闲表单命令提示符?

Is there any way so that i can type idle test.py on cmd so that it opens the test.py file in the current directory and if test.py is not available creates a new file and opens it into idle 是否有任何方法可以在cmd上键入idle test.py ,以便在当前目录中打开test.py文件,如果test.py不可用则创建一个新文件并将其打开为空闲状态

You can do that by adding the directory where you have installed the idle editor the PATH environment variable. 您可以通过添加已安装idle编辑器PATH环境变量的目录来实现。

How to do that depends on your operating system: just search the Internet for add directory to path plus your operating system: eg Windows/Ubuntu, etc. 如何做到这一点取决于您的操作系统:只需在Internet上搜索add directory to path和操作系统的add directory to path :例如Windows / Ubuntu等。

After changing the environment variable it may be a good idea to restart your PC (to make sure that all programs use the updated version) 更改环境变量后,重新启动PC可能是个好主意(以确保所有程序都使用更新版本)

You can right click on the idle then you will can see location of it in the properties tab 您可以右键单击空闲,然后您可以在属性选项卡中查看它的位置

Navigate to that location and call as below 导航到该位置并按如下方式拨打电话

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 2.7>"IDLE (Python GUI).lnk" C:\Python27\projects\ping.py

Create a idle.bat file containing 创建一个包含的idle.bat文件

@echo off
{Python path}\Lib\idlelib\idle "%cd%\%1"

Where {Python path} should be replaced with the directory where python is installed. 其中{Python path}应该替换为安装python的目录。

Example :- 示例 : -

@echo off
C:\Python36\Lib\idlelib\idle "%cd%\%1"

Copy this idle.bat file into the python directory ie {Python path} (C:\\Python36 in case of the example) 将此idle.bat文件复制到python目录即{Python path}(例如,C:\\ Python36)

Make sure you've add python path to environment variables 确保您已将python路径添加到环境变量中

Open cmd in your folder then type 在文件夹中打开cmd,然后键入

idle test.py

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

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