关于本人的package,情况比较简单,所有的.py文件全部放到了一个叫做FundsData的文件夹下(package下),上层目录也叫FundsData(其实叫什么都可以),其下放了setup.py. 关于具体情况,请参见GitHub上的内容:https://github.com/FinixLei/FundsData
而setup.py 的内容如下:
[python] view plain copy
from distutils.core import setup
PACKAGE = “FundsData”
NAME = “FundsData”
DESCRIPTION = “This package can download funds data from http://huobijijin.com and then analyze the data for giving valuable funds.”
AUTHOR = “Finix Lei”
AUTHOR_EMAIL = “finixlei@gmail.com”
URL = “https://github.com/FinixLei/FundsData”
VERSION = __import__(PACKAGE).__version__
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
# long_description=read(“README.md”),
author=AUTHOR,
author_email=AUTHOR_EMAIL,
license=“Apache License, Version 2.0”,
url=URL,
packages=[“FundsData”],
classifiers=[
“Development Status :: 3 – Alpha”,
“Environment :: Web Environment”,
“Intended Audience :: Developers”,
“Operating System :: OS Independent”,
“Programming Language :: Python”,
],
zip_safe=False,
)
要想成功运行setup.py将自己的python脚本打包上传到PYPI上,首先要安装setuptools包。在Windows上只要下载个windows专用的python 2.7,自然就有了setuptools和distutils;而在Linux上,要自己用pip装一下,或者运行下python ez_setup.py来安装。至于哪里去弄ez_setup.py,网上一搜到处是,就不赘述了。
关于setuptools和distutils的区别,我这里的描述不够清晰,大家可以参看:http://www.cnblogs.com/aguncn/p/3427707.html
当有了distutils之后(一般都有,这是自带的),运行如下命令就可以在PYPI上注册、自己build并上传到PYPI上了:
[plain] view plain copy
python setup.py register sdist upload
但是,是如何连上PYPI的呢?当然,你要先注册一个帐号。然后写一个.pypirc文件如下,并将其放到~目录下:
[plain] view plain copy
[distutils]
index-servers = pypi
[pypi]
username:xxx
password:yyy
好了,一切成功后,你就可以看到类似这样的网页生成在PYPI上了:
https://pypi.python.org/pypi/FundsData
如README.md所述,使用pip的安装方法如下:
[plain] view plain copy
sudo pip install FundsData
运行方法为:
[plain] view plain copy
python -mFundsData.funds_data -h
python -mFundsData.funds_data