py格式的py文件如何运行怎么运行

& & 编写setup.py文件,获取帮助:python setup.py --help-commands& & [python]& & Standard commands:& & build&&&&&&&&&&&&build everything needed to install& & build_py&&&&&&&&&"build" pure Python modules (copy to build directory)& & build_ext&&&&&&&&build C/C++ extensions (compile/link to build directory)& & build_clib&&&&&&&build C/C++ libraries used by Python extensions& & build_scripts&&&&"build" scripts (copy and fixup #! line)& & clean&&&&&&&&&&&&clean up temporary files from 'build' command& & install&&&&&&&&&&install everything from build directory& & install_lib&&&&&&install all Python modules (extensions and pure Python)& & install_headers&&install C/C++ header files& & install_scripts&&install scripts (Python or otherwise)& & install_data&&&&&install data files& & sdist&&&&&&&&&&&&create a source distribution (tarball, zip file, etc.)& & register&&&&&&&&&register the distribution with the Python package index& & bdist&&&&&&&&&&&&create a built (binary) distribution& & bdist_dumb&&&&&&&create a "dumb" built distribution& & bdist_rpm&&&&&&&&create an RPM distribution& & bdist_wininst&&&&create an executable installer for MS Windows& & upload&&&&&&&&&&&upload binary package to PyPI& & check&&&&&&&&&&&&perform. some checks on the package& & Extra commands:& & rotate&&&&&&&&&&&delete older distributions, keeping N newest files& & develop&&&&&&&&&&install package in 'development mode'& & setopt&&&&&&&&&&&set an option in setup.cfg or another config file& & saveopts&&&&&&&&&save supplied options to setup.cfg or other config file& & egg_info&&&&&&&&&create a distribution's .egg-info directory& & install_egg_info&Install an .egg-info directory for the package& & alias&&&&&&&&&&&&define a shortcut to invoke one or more commands& & easy_install&&&&&Find/get/install Python packages& & bdist_egg&&&&&&&&create an "egg" distribution& & test&&&&&&&&&&&&&run unit tests after in-place build& & standard commands(标准命令)是distutils内建命令,而Extra commands(附加命令)是像& & setuptools这样的第三方包创建的。& & 命令详解:& & 1.sdist:用来创建一个源码包,在windows下为zip格式,linux下为tag.gz格式 。& & setup.py示例:& & from setuptools import setup& & setup(name='xxx',version='0.1.1')& & 打包命令:python setup.py sdist& & distutils将浏览包的路径,查找包含在档案中的文件,包括:& & 1)所有py_modules、packages和scripts选项隐含的python源文件& & 2)所有在ext_modules选项中列出的C源文件& & 3)符合test/test*.py模式的文件& & 4)README、README.txt、setup.py和setup.cfg文件& & 如果需要包含更多文件,那么可以使用MANIFEST.in文件模版,示例如下:& & include xx.txt& & include yy/xx.txt& & ....& & 2.bdist_egg:用来创建一个二进制分发版本,经常用来替代基于bdist生成的模式& & 3.install:安装包到python中。另外,他还可能会安装在setup.py中的install_requires定义的& & 相关模块,例如:& & install_requires=['...','...']& & 删除一个包:1)删除这个包所创建的文件,2)删除在site-packages文件夹easy-install.pth文& & 件中列举的所有引用。 & & 4.develop:编译并且在适当的位置安装包,然后添加一个简单的链接到python site-packages文& & 件夹中,可以使用显式的-u选项删除包,例如:& & python setup.py develop& & python setup.py develop -u& & 使用该方式比其他方式安装包更好一些& & 5.创建一个新命令:这是由setuptools引入的,是一种将包定义为插件的简单方法,示例:& & ...entry_points='''& & [mands]& & my_mand.module.Class
声明:该文章系网友上传分享,此内容仅代表网友个人经验或观点,不代表本网站立场和观点;若未进行原创声明,则表明该文章系转载自互联网;若该文章内容涉嫌侵权,请及时向
论文写作技巧
上一篇:下一篇:
相关经验教程Python脚本文件打包成可执行文件的方法
将Python脚本文件包装成可执行文件,其目的有二:
一则: 不需要依赖Python编译器就可以运行软件
二则: 不想让自己的源码公布出去
常用的工具有: py2exe、cx_freeze等
【工具:py2exe】
安装py2exe
安装该工具很简单:
只需要从官方网站:http://www.py2exe.org/下载与版本对应的安装程序,点击下一步即可完成安装。
安装后,执行import py2exe,不报错则表示安装成功!
&&& import py2exe&
NOTE: 目前该工具只支持到Python2.7, 对于Python3而言,必须借助另外一个工具:cx_freeze
使用py2exe
第一步: 准备源代码,假如名为:Hello.py
第二步: 准备编译脚本,假如名为:setup.py
from distutils.core import setup&
import py2exe&
setup(windows=['Hello.py'])&
第三步: 运行命令: setup.py py2exe
D:\temp&setup.py py2exe
运行之后,会在我当前运行的目录下(D:\temp)默认生成dict目录,里面的文件如下:
默认情况下,py2exe在目录dist下创建以下这些必须的文件:&
1、一个或多个exe文件。如本例为: Hello.exe&
2、python##.dll。 如本例中: Python27.dll&
3、.pyd文件,它们是已编译的扩展名,它们是exe文件所需要的;加上其它的.dll文件,这些.dll是.pyd所需要的。&
4、一个library.zip文件,它包含了已编译的纯的python模块如.pyc或.pyo&
第四步: 双击Hello.exe可执行文件,跟源代码运行后同样的结果:
1: 执行setup.py --help获取帮助信息
Global options:&
& --verbose (-v)& run verbosely (default)&
& --quiet (-q)&&& run quietly (turns verbosity off)&
& --dry-run (-n)& don't actually do anything&
& --help (-h)&&&& show detailed help message&
& --no-user-cfg&& ignore pydistutils.cfg in your home directory&
Options for 'py2exe' command:&
& --optimize (-O)&&&&&& optimization level: -O1 for "python -O", -O2 for&
&&&&&&&&&&&&&&&&&&&&&&& "python -OO", and -O0 to disable [default: -O0]&
& --dist-dir (-d)&&&&&& directory to put final built distributions in (default&
&&&&&&&&&&&&&&&&&&&&&&& is dist)&
& --excludes (-e)&&&&&& comma-separated list of modules to exclude&
& --dll-excludes&&&&&&& comma-separated list of DLLs to exclude&
& --ignores&&&&&&&&&&&& comma-separated list of modules to ignore if they are&
&&&&&&&&&&&&&&&&&&&&&&& not found&
& --includes (-i)&&&&&& comma-separated list of modules to include&
& --packages (-p)&&&&&& comma-separated list of packages to include&
& --compressed (-c)&&&& create a compressed zipfile&
& --xref (-x)&&&&&&&&&& create and show a module cross reference&
& --bundle-files (-b)&& bundle dlls in the zipfile or the exe. Valid levels&
&&&&&&&&&&&&&&&&&&&&&&& are 1, 2, or 3 (default)&
& --skip-archive&&&&&&& do not place Python bytecode files in an archive, put&
&&&&&&&&&&&&&&&&&&&&&&& them directly in the file system&
& --ascii (-a)&&&&&&&&& do not automatically include encodings and codecs&
& --custom-boot-script& Python file that will be run when setting up the&
&&&&&&&&&&&&&&&&&&&&&&& runtime environment&
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]&
&& or: setup.py --help [cmd1 cmd2 ...]&
&& or: setup.py --help-commands&
&& or: setup.py cmd --help&
2: 一个详细的编译脚本
# -*- coding: cp936 -*-&
from distutils.core import setup&
import py2exe&
includes = ["encodings", "encodings.*"]&
options = {"py2exe":&&&
&&&&&&&&&&& {"compressed": 1,&&&&& # 压缩&&&
&&&&&&&&&&&& "optimize": 2,&&&&&&& # 优化级别&
&&&&&&&&&&&& "ascii": 1,&&&&&&&&&& #&&
&&&&&&&&&&&& "includes":includes,& # 编码方式&
&&&&&&&&&&&& "bundle_files": 1&&&& # 所有文件打包成一个zipfile或exe文件,有效级别1,2,3&
&&&&&&&&&&& }}&
&&& options=options,&&&&&&&&&&&&&& # 是否需要可选项,默认为None&
&&& zipfile=None,&&&&&&&&&&&&&&&&& # 是否需要压缩像,默认为None&
&&& console=[{"script": "HelloCmd.py", "icon_resources": [(1, "pc.ico")]}], # 针对CMD控制端口&&
&&& windows=[{"script": "HelloWin.py", "icon_resources": [(1, "pc.ico")]}], # 针对GUI图形窗口&
&&& data_files=[("magic",["App_x86.exe",]),],&
&&& version = "v1.01",&&&&&&&&&&&& # 版本信息&
&&& description = "py2exe testing",# 描述信息&&
&&& name = "Hello, Py2exe",&&&&&&& # 名字信息&
如果您喜欢本文请分享给您的好友,谢谢!
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)苹果/安卓/wp
积分 201, 距离下一级还需 59 积分
权限: 自定义头衔
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡下一级可获得
权限: 签名中使用图片
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
苦逼签到天数: 9 天连续签到: 1 天[LV.3]偶尔看看II
python软件的py文件可以逐行逐行运行吗?好像按F5就一下全运行了。请问大神们有没有什么方法可以让python脚本逐步运行的方法?
希望能够边一边编写代码保存一边可以运行调试,类似matlab,R-studio那种。在shell里面可以运行但不能保存代码,在py文件中可以保存但不能逐步运行。
支持楼主:、
购买后,论坛将把您花费的资金全部奖励给楼主,以表示您对TA发好贴的支持
载入中......
我用wing IDE 101可以逐行运行,点击右键有一个运行所选行的选项。python本身自己如何逐行运行我也不知道怎么做到。
lz用的什么ide ?貌似spyder可以逐行debug的。
本帖最后由 letsgoaway 于
09:56 编辑 adjfa 发表于
lz用的什么ide ?貌似spyder可以逐行debug的。本来是用自带的idle的,发现不行我就下了一个sublime text,发现它也是所有代码一起运行的[cry][cry],不知道是需要调设置,还是编辑器本身就没法逐行运行。
不是要debug,是要逐行运行的,就是在.py文件里面一行一行运行。
无限扩大经管职场人脉圈!每天抽选10位免费名额,现在就扫& 论坛VIP& 贵宾会员& 可免费加入
加入我们,立即就学扫码下载「就学」app& Join us!& JoinLearn&
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师11046人阅读
python入门(3)
废话不多说,就讲一下这个背景吧:
事情是这个样子的~ 本着好学的精神,咱就买了本书,学习python结果呢,发现python的教程都是一个样子滴,上来的第一个hello world 都是通过IDLE来实现的。这个就比较让我头疼了,这个太简单了啊。可是我该肿么脱离IDLE来编写自己的python模块呢。于是乎,就有了这个文章
一、先讲一下我的操作步骤吧,后面再统一简单介绍下这个内容(只适合初学者,高手们略过~~):
前提是你电脑装了python哈,没有装python是不可以运行滴~~
1.新建一个文本文件:
&& &将文件名称更改为 HelloWorld.py(文件名随便起) 注意要修改文件的后缀名字哦,大家应该都会,就不多说了。
2.使用记事本打开这个文件,在里面敲入如下代码:
import sys,os
def PrintSomeThing():
print(os.path.dirname(os.sys.argv[0]))
raw_input()
if __name__ == &__main__&:
PrintSomeThing()
3.双击运行该文件,歘歘歘~~好咧 。文件成功运行了。
二、简单描素下吧
第一行:引入一个包,os和sys。这俩都是系统的模块,因为下面我们用到了os和sys两个函数,是需要这俩模块的,所以要引入。
第二行代码到第四行代码 定义了一个函数,函数的作用就是 1.输出脚本所在目录 2.让命令窗口等待用户输入
代码第五六行 这里是这个文章的关键咯:
有了这个,你直接双击运行这个文件的话,python就会执行main下面的函数咯。所以就会执行输出路径。。。
注意哇,这个语句中下划线是两个昂即__是连续两个_ _看清哦。要不然也是会出错哟。
好吧。先记录这些吧。小小的成就感,不喜勿喷~~
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:830505次
积分:10398
积分:10398
排名:第1178名
原创:184篇
转载:22篇
译文:18篇
评论:416条
文章:11篇
阅读:15697
阅读:25470
阅读:11220
文章:37篇
阅读:259700

我要回帖

更多关于 py文件如何运行 的文章

 

随机推荐