如何通过Python制作并封装Python包为可用模块?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1231个文字,预计阅读时间需要5分钟。
首先编写py程序:`printtest.py`pythondef test(): print('print test')将以上.py文件做成python模块,需要在相同目录下创建`setup.py`文件,内容如下:pythonfrom setuptools import setup
setup( name='printtest', version='0.1',)
首先编写py程序:
printtest.py
def test():
print('print test')
将以上.py文件做成python模块,需要在相同目录下创建setup.py文件,setup.py中输入配置信息:
from setuptools import setup setup(name='printtest', version='1.0', py_modules=['printtest'], )
打开终端,定位到该文件夹下,输入:
python setup.py sdist
此时在目录中生成dist文件夹,文件夹中有testpg-1.0.tar.gz文件,用户安装的话只需要testpg-1.0.tar.gz文件即可。
本文共计1231个文字,预计阅读时间需要5分钟。
首先编写py程序:`printtest.py`pythondef test(): print('print test')将以上.py文件做成python模块,需要在相同目录下创建`setup.py`文件,内容如下:pythonfrom setuptools import setup
setup( name='printtest', version='0.1',)
首先编写py程序:
printtest.py
def test():
print('print test')
将以上.py文件做成python模块,需要在相同目录下创建setup.py文件,setup.py中输入配置信息:
from setuptools import setup setup(name='printtest', version='1.0', py_modules=['printtest'], )
打开终端,定位到该文件夹下,输入:
python setup.py sdist
此时在目录中生成dist文件夹,文件夹中有testpg-1.0.tar.gz文件,用户安装的话只需要testpg-1.0.tar.gz文件即可。

