一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - 利用setuptools打包python程序的方法步驟

利用setuptools打包python程序的方法步驟

2020-04-16 12:52風(fēng)間悠香 Python

這篇文章主要介紹了利用setuptools打包python程序的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一、準(zhǔn)備工程文件

1.創(chuàng)建工程leeoo

利用setuptools打包python程序的方法步驟

2.在工程根目錄下創(chuàng)建setup.py文件

利用setuptools打包python程序的方法步驟

3.在工程根目錄下創(chuàng)建同名package

利用setuptools打包python程序的方法步驟

二、編輯setup.py

1.編輯setup.py文件

?
1
2
3
4
5
6
7
8
9
10
11
from setuptools import setup, find_packages
 
setup(
  name='leeoo', # 包的名稱
  version='1.0', # 版本號
  packages=find_packages(), # 動(dòng)態(tài)獲取packages
  description="leeoo package",
  author='Leo',
  author_email='[email protected]',
  url="None",
)

2.參數(shù)說明

利用setuptools打包python程序的方法步驟

三、編寫測試代碼

1.在leeoo package下創(chuàng)建pkg

利用setuptools打包python程序的方法步驟

2.test.py文件內(nèi)容

?
1
2
3
4
5
6
7
8
9
10
11
def testfunc():
  print("This is a test function..")
 
 
class TestClass(object):
  def __init__(self, name):
    self.name = name
    print("This is a test Class..")
 
  def get_name(self):
    return self.name

3.將test.py中的內(nèi)容全部導(dǎo)入到leeoo的__init__.py中

利用setuptools打包python程序的方法步驟

這樣,以后import leeoo后,就可以直接使用leeoo.testfunc()了。

四、打包

1.命令行進(jìn)入工程根目錄

利用setuptools打包python程序的方法步驟

2.運(yùn)行命令

?
1
2
(venv) D:\pycharm_workspace\leeoo>python setup.py check
running check
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(venv) D:\pycharm_workspace\leeoo>python setup.py bdist_egg
running bdist_egg
running egg_info
creating leeoo.egg-info
writing leeoo.egg-info\PKG-INFO
writing dependency_links to leeoo.egg-info\dependency_links.txt
writing top-level names to leeoo.egg-info\top_level.txt
writing manifest file 'leeoo.egg-info\SOURCES.txt'
reading manifest file 'leeoo.egg-info\SOURCES.txt'
writing manifest file 'leeoo.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\leeoo
copying leeoo\__init__.py -> build\lib\leeoo
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\leeoo
copying build\lib\leeoo\__init__.py -> build\bdist.win-amd64\egg\leeoo
byte-compiling build\bdist.win-amd64\egg\leeoo\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\leeoo-1.0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)

3.查看生成的文件

在工程根目錄下,可以看到生成了一系列文件:

利用setuptools打包python程序的方法步驟

五、安裝leeoo

1.在工程目錄下(setup.py所在目錄)運(yùn)行命令

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
D:\pycharm_workspace\leeoo>python setup.py install
running install
running bdist_egg
running egg_info
writing leeoo.egg-info\PKG-INFO
writing dependency_links to leeoo.egg-info\dependency_links.txt
writing top-level names to leeoo.egg-info\top_level.txt
reading manifest file 'leeoo.egg-info\SOURCES.txt'
writing manifest file 'leeoo.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\leeoo
copying build\lib\leeoo\__init__.py -> build\bdist.win-amd64\egg\leeoo
byte-compiling build\bdist.win-amd64\egg\leeoo\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying leeoo.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\leeoo-1.0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing leeoo-1.0-py3.7.egg
Copying leeoo-1.0-py3.7.egg to d:\dev_apps\anaconda5.3.0\lib\site-packages
Adding leeoo 1.0 to easy-install.pth file
 
Installed d:\dev_apps\anaconda5.3.0\lib\site-packages\leeoo-1.0-py3.7.egg
Processing dependencies for leeoo==1.0
Finished processing dependencies for leeoo==1.0

2.查看安裝好的文件

我們看到上述打印日志中,將leeoo-1.0-py3.7.egg安裝到了d:\dev_apps\anaconda5.3.0\lib\site-packages。

利用setuptools打包python程序的方法步驟

六、使用leeoo

新建一個(gè)項(xiàng)目,然后導(dǎo)入leeoo:

?
1
2
3
4
5
import leeoo
 
leeoo.testfunc()
obj = leeoo.TestClass("demo")
print(obj.get_name())

也可以使用:

?
1
2
3
4
5
from leeoo.pkg import test
 
test.testfunc()
obj = test.TestClass("demo")
print(obj.get_name())

當(dāng)然也可以直接將testfunc()和TestClass導(dǎo)入,但是容易引起命名沖突。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://www.cnblogs.com/leokale-zz/p/12207923.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产男人搡女人免费视频 | 国产手机在线αⅴ片无码观看 | 农村妇女野外性生话免费视频 | 久久国产免费 | 欧美色图亚洲天堂 | 免费看一级 | 美女福利视频午夜在线 | 双性肉文高h | 国产情侣啪啪 | 富士av105| 女子校生下媚药在线观看 | 亚洲国产五月综合网 | 香蕉久久一区二区不卡无毒影院 | 日本xxwwwxxxx | 日本黄色录像视频 | 久久九九亚洲精品 | 男人的天堂久久 | 亚洲成人aa | 无人在线高清免费看 | 香蕉精品高清在线观看视频 | 丫鬟粗大狠狠贯穿h | 免费一级欧美片在线观看 | 26uuu成人人网图片 | 波多野结衣女教师在线观看 | 国产成人一区二区三区小说 | 成年看片免费高清观看 | tolove第一季动画在线看 | 精品国产在天天线在线麻豆 | 欧美成年黄网站色高清视频 | 亚洲国产欧美在线人成aaa | 鄂州一家三口完整版免费 | 四虎在线永久免费视频网站 | 亚洲精品一二三四 | 国产极品麻豆91在线 | 啪啪免费入口网站 | 欧美女人p | 果冻传媒 天美 麻豆 | 四虎影院免费在线播放 | 男人的j进入女人的j免费 | 久久婷婷五月综合色丁香花 | www日本高清视频 |