python库文件打包_使用可执行文件打包Python库

通常,当整个项目适合单个模块文件时,您只将python包作为模块分发.如果您的项目比这更复杂,通常最好将项目构造为包含__init__.py文件的包.这是您的项目看起来像转换为包的内容

Project/

|-- README

|-- requirement.txt

|-- setup.py

|-- scripts/

| |-- driver.py

|-- driver/

| |-- __init__.py

| |-- module_1

| | |-- __init__.py

| | |-- class_1.py

| | |-- class_2.py

| |-- module_2

| |-- |-- __init__.py

| |-- |-- class_1.py

| |-- |-- class_2.py

我将run.py重命名为scripts / driver.py,而之前在driver.py中的代码现在是driver / __ init__.py.

你的setup.py应该是这样的

from setuptools import setup. find_packages

setup(

name='driver',version='1.0',packages=find_packages(),scripts=['scripts/driver.py'],)

这会将scripts / driver.py复制到python Scripts目录.我将run.py重命名为driver.py,因为run非常通用,并且您希望脚本名称是唯一的,因为所有python包共享相同的脚本位置.

或者,您可以使用console_scripts入口点.在这种情况下,您将没有单独的scripts / driver.py脚本.相反,你只需要在你的包中有一个功能.在这种情况下,您可以将脚本/ driver.py中的所有代码移动到driver / command_line.py中,并将其放在名为main()的函数中.然后将setup.py更改为此

setup(

name='driver',entry_points = {

'console_scripts': ['driver=driver.command_line:main'],}

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值