1、需求python
双击py文件,运行,并查看运行结果。bash
2、容易出现的问题:.net
(1)双击后没有运行程序,而是调出python编译器,查看代码。code
(2)双击后一闪而过,看不到运行结果。blog
3、具体操做以下ip
第一步 安装pythonget
如,安装在 C:\python27input
第二步 配置环境变量(以win7为例)编译器
右键个人电脑-->属性-->高级系统设置-->环境变量-->系统变量-->选择path-->添加:it
;C:\python27\;C:\python27\Scripts
第三步 写python代码
#!/usr/bin/python # -*- coding: UTF-8 -*- def double_click_run_py(): for i in range(1,5): print u'我今天吃了%s个苹果' % i if __name__ == '__main__': print("Start to run py file.........") double_click_run_py() print("Finished, please check results.........") input("\n\nPress the ENTER key to exit.")
注意最后一句:input(“Enter the any press to exit” )。不少人说的双击一闪而过,就是程序最后没有输入操做,致使直接退出了。
第四步 保存py文件,并修改文件属性
如 eatApple.py。
注意选择浏览文件的时候,要选择python的安装路径下的python.exe,如C:\python27
第五步 运行便可,按回车键可退出。
参考 http://blog.csdn.net/RobertChenGuangzhi/article/details/50598949