栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Python 打包 setup.py 通用模版

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 打包 setup.py 通用模版

setup.py 通用简易模版 快速打包(只有pyx文件)
from setuptools import setup, Extension
import numpy as np # if using cimport numpy in pyx file

extensions = [
	Extension(
		“extention_name”, # name
		sources=[“pyx_file_name.pyx”], # pyx file
		include_dirs=[np.get_include()] # if using cimport numpy
	)
]

setup(ext_modules=cythonize(extensions, language_level=3))

打包cpp/c文件

这个文件也可以是用pyx生成的

from setuptools import setup, Extension

extensions = [
	Extension(
	“test”, # name
	sources=[“test.cpp”], # pyx file
	language='c++',
	include_dirs=['/usr/local/include', np.get_include(), 'some_package/include'], # folders that have all .h files, -I option
	libraries=['EGL', 'glfw'], # -l option
	library_dirs=['usr/local/lib'], # -L option
	extra_compile_args=['-std=c++11'] # other options if needed
	)
]

setup(
	name='test-package',
	version='1.0.0',
	setup_requires=['numpy'],
	install_requires=['numpy>=1.18.0'],
	python_requires='~=3.6', # >= 3.6, < 4.0
	ext_modules=extensions,
	packages=find_packages(), # if has other py files in this package
	include_package_data=True, # to include generated so file to directly use in other py files
	description='test packaging...'
)

打包命令
  • pyx --> cpp
cython -3 --fast-fail -v --cplus file_name.pyx
  • 打包成so文件
python setup.py build_ext --inplace
  • 打包成whl文件
python setup.py sdist bdist_wheel
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/605233.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号