Python项目打包二进制文件并发布
- 复制项目
- 生成二进制文件(交叉编译???)
- 重命名二进制文件
- 生成pyi文件(编译器智能提示需要
- 删除原始py文件(复制后的)
- 项目打包上传(分版本分平台???)
流程、代码待完善
二进制文件生成
pip install cpython
# setup.py
def find_pyx_files(directory):
pyx_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
module = os.path.relpath(os.path.join(root, file), directory)
module = module.replace(os.path.sep, ".")[:-4]
pyx_files.append((module, os.path.join(root, file)))
return pyx_files
ext_modules = [
Extension("*", [source]) for _, source in find_pyx_files(os.path.join(os.path.dirname(__file__), 'dir'))
]
setup(
name='',
version='',
author='',
author_email='',
description='打包示例',
url='',
packages=find_packages(),
ext_modules=cythonize(f_name),
zip_safe=False,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=[ # 添加了依赖的 package
],
python_requires='>=3.6',
)
python setup.py build_ext --inplace
pyi文件生成
pip install mypy
stubgen temp.py