加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 将Cython标记为构建依赖关系?

发布时间:2020-12-16 21:49:39 所属栏目:Python 来源:网络整理
导读:有一个带有setup.py的Python包,可以这样读取: from distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Distutils import build_extsetup( name = 'fastahack',ext_modules=[ Extension("fastahack.cfastahack",sources=["f

有一个带有setup.py的Python包,可以这样读取:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
  name = 'fastahack',ext_modules=[
    Extension("fastahack.cfastahack",sources=["fastahack/cfastahack.pyx","lib/Fasta.cpp","lib/split.cpp"],libraries=["stdc++"],include_dirs=["lib/"],language="c++"),],package_data = {'lib': ['*.pyx',"*.c","*.h","README.rst"]},package_dir = {"fastahack": "fastahack"},cmdclass = {'build_ext': build_ext},packages = ['fastahack','fastahack.tests'],author = "Brent Pedersen",author_email="bpederse@gmail.com",#test_suite='nose.collector'
)

如果未安装Cython,则无法导入此setup.py.据我所知,导入setup.py是像pip这样的工具如何找出包的依赖关系.我想设置这个包,以便它可以上传到PyPI,事实上它依赖于Cython注意到,所以当你尝试“pip install fastahack”时,或当你试图“下载”时,将下载并安装Cython pip install“直接来自Git存储库.

我如何打包此模块,以便在未安装Cython时从Internet正确安装?始终使用最新版本的Cython将是一个加号.

最佳答案
我的setup.py标准模板:

have_cython = False
try:
    from Cython.Distutils import build_ext as _build_ext
    have_cython = True
except ImportError:
    from distutils.command.build_ext import build_ext as _build_ext

if have_cython:
    foo  = Extension('foo',['src/foo.pyx'])
else:
    foo  = Extension('foo',['src/foo.c'])

setup (
   ...
   ext_modules=[foo],cmdclass={'build_ext': build_ext}

并且不要忘记提供带有包的扩展.c文件 – 这将允许用户在不安装cython的情况下构建模块.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读