我創建一個Python包與C++擴展setuptools的。我試圖用setuptools來做到這一點,因爲這似乎是首選解決方案。鑑於它允許setup_requires,install_requires,我同意並將其用於我的python only軟件包。但是,當我有一個C++擴展模塊時,我無法使它工作。然後我使用distutils.core來使其工作。我想知道如何使用setuptools來使用它。我的安裝腳本看起來像distutils.core VS與C++擴展
from setuptools import setup
import shutil
import os
# folder where .so is being build by cpp compilation
so_src = os.path.join(dir, 'cpp/build/')
# folder where .so should live in python package
so_des = os.path.join(dir, 'package_py/cpp/')
# extension module
lib_files = ['cpp_py.so']
# copy shared lib
for f in lib_files:
shutil.copyfile(so_src + f, so_des + f)
# set-up script
setup(
name=DISTNAME
, version=FULLVERSION
, description= DESCRIPTION
, author= AUTHOR
, author_email= EMAIL
, maintainer= AUTHOR
, maintainer_email= EMAIL
, long_description=LONG_DESCRIPTION
, packages=['package_py',
'package_py.cpp']
, package_dir={'package_py.cpp': 'package_py/cpp'}
, package_data={'package_py.cpp': lib_files}
)
這導致我的Python站點包一個package_py-0.0.1-py3.6.egg文件。包只有適用於從安裝文件夾使用。
改變第一線使用distutils.core而不是setuptools的
from distutils.core import setup # only change, remainder is the same!!
import shutil
import os
# folder where .so is being build by cpp compilation
so_src = os.path.join(dir, 'cpp/build/')
# folder where .so should live in python package
so_des = os.path.join(dir, 'package_py/cpp/')
# extension module
lib_files = ['cpp_py.so']
# copy shared lib
for f in lib_files:
shutil.copyfile(so_src + f, so_des + f)
# set-up script
setup(
name=DISTNAME
, version=FULLVERSION
, description= DESCRIPTION
, author= AUTHOR
, author_email= EMAIL
, maintainer= AUTHOR
, maintainer_email= EMAIL
, long_description=LONG_DESCRIPTION
, packages=['package_py',
'package_py.cpp']
, package_dir={'package_py.cpp': 'package_py/cpp'}
, package_data={'package_py.cpp': lib_files}
)
我得到一個package_py文件夾(與.so文件)和package_py-0.0.1-py3.6.egg-信息在網站-packages。現在該模塊在所有文件夾中工作。
,因爲我想延長Python包也使用setup_requires,instal_requires我想真正使用setuptools的。我怎樣才能獲得包使用setuptools的,而不是distutils.core