将自己制作的python包安装到Linux系统中

1.新建setup.py文件,并将下面代码修改后复制到文件中

from distutils.core import setup

setup(name="qiracle",version="1.0",description="qiracle's module",author="qiracle",py_modules=["test1","test2"])

这里py_modules列表里填的是模块的名字

2.python3 setup.py build

执行完后出现:

running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying test1.py -> build/lib.linux-x86_64-2.7
copying test2.py -> build/lib.linux-x86_64-2.7

3.python3 setup.py sdist

执行完后出现:

running sdist
running check
warning: check: missing required meta-data: url
warning: check: missing meta-data: if ‘author’ supplied, ‘author_email’ must be supplied too
warning: sdist: manifest template ‘MANIFEST.in’ does not exist (using default file list)
warning: sdist: standard file not found: should have one of README, README.txt
writing manifest file ‘MANIFEST’
creating qiracle-1.0
making hard links in qiracle-1.0…
hard linking setup.py -> qiracle-1.0
hard linking test1.py -> qiracle-1.0
hard linking test2.py -> qiracle-1.0
creating dist
Creating tar archive
removing ‘qiracle-1.0’ (and everything under it)

4.找到模块的压缩包,解压,进入setup.py所在文件夹后执行命令:

python3 setup.py install(需要管理员权限)

执行完后出现:

running install
running build
running build_py
running install_lib
copying build/lib/test2.py -> /usr/local/lib/python3.4/dist-packages
copying build/lib/test1.py -> /usr/local/lib/python3.4/dist-packages
byte-compiling /usr/local/lib/python3.4/dist-packages/test2.py to test2.cpython-34.pyc
byte-compiling /usr/local/lib/python3.4/dist-packages/test1.py to test1.cpython-34.pyc
running install_egg_info
Writing /usr/local/lib/python3.4/dist-packages/qiracle-1.0.egg-info

此时表明安装成功,在之后的python程序中任意路径下都可直接import包名使用

你可能感兴趣的:(Python,linux)