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

python– 将Cython标记为构建依赖关系?,第1张

概述有一个带有setup.py的Python包,可以这样读取:from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( name = 'fastahack', ext_m

有一个带有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=["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="[email protected]",#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 = Falsetry:    from Cython.distutils import build_ext as _build_ext    have_cython = Trueexcept importError:    from distutils.command.build_ext import build_ext as _build_extif 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的情况下构建模块. 总结

以上是内存溢出为你收集整理的python – 将Cython标记为构建依赖关系?全部内容,希望文章能够帮你解决python – 将Cython标记为构建依赖关系?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1205307.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存