有一个带有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}