Head Frist Python 读书笔记 构建发布
构建发布 p41
Windows系统需要使用“c:\pythonX\python.exe”执行,
或者,通过配置环境变量来简化输入
1. 首先需要在系统中注册python环境变量:假设python的安装路径为c:\python2.6,则修改我的电脑->属性->高级->环境变量->系统变量中的PATH为:
(为了在命令行模式下运行Python命令,需要将python.exe所在的目录附加到PATH这个环境变量中。)
PATH=PATH;c:\python26
上述环境变量设置成功之后,就可以在命令行直接使用python命令。或执行"python *.py"运行python脚本了。
2. 此时,还是只能通过"python *.py"运行python脚本,若希望直接运行*.py,只需再修改另一个环境变量PATHEXT:
PATHEXT=PATHEXT;.PY;.PYM
setup.py文件,是用于打包发布的索引文件,调用了distutils.core.setup方法,其中py_modules标明了需要打包文件的名字
from distutils.core import setup setup( name="nester", version="1.0.0", py_modules=['nester'], author="abc", author_email="abc@def.com", url="http://localhost/", description="A simple printer of nested lists", )
构建一个发布文件:
将发布安装到Python本地副本中:
书中使用的是,这个是Linux的命令
sudo python3 setup.py install
Windows中使用
python setup.py install
命令说明:
python setup.py sdist
(assuming you haven’t specified any sdist options in the setup script or config file), sdist creates the archive of the default format for the current platform. The default format is a gzip’ed tar file (.tar.gz) on Unix, and ZIP file on Windows.
You can specify as many formats as you like using the --formats option, for example:
python setup.py sdist --formats=gztar,zip
to create a gzipped tarball and a zip file. The available formats are:
Format | Description | Notes |
---|---|---|
zip | zip file (.zip) | (1),(3) |
gztar | gzip’ed tar file (.tar.gz) | (2) |
bztar | bzip2’ed tar file (.tar.bz2) | |
ztar | compressed tar file (.tar.Z) | (4) |
tar | tar file (.tar) |
Notes:
- default on Windows
- default on Unix
- requires either external zip utility or zipfile module (part of the standard Python library since Python 1.6)
- requires the compress program. Notice that this format is now pending for deprecation and will be removed in the future versions of Python.
When using any tar format (gztar, bztar, ztar or tar), under Unix you can specify the owner and group names that will be set for each member of the archive.
For example, if you want all files of the archive to be owned by root:
python setup.py sdist --owner=root --group=root
tips:“打开一个终端窗口”,可以通过命令行cd到代码所在目录,也可以在所在目录shift+鼠标右键,调出命令窗口
posted on 2015-11-14 16:05 Lv Jianwei 阅读(327) 评论(0) 编辑 收藏 举报