目前,我采用了以下解决方案,需要导入numpy。到目前为止,它没有引起任何问题。
setup.py
from setuptools import setup
from setuptools.extension import Extension
import numpy as np
import versioneer
project_name = 'foobar'
long_description = """
Long description in RST. Used by PyPI.
"""
versioneer.VCS = 'git'
versioneer.versionfile_source = project_name + '/_version.py'
versioneer.versionfile_build = project_name + '/_version.py'
versioneer.tag_prefix = ''
versioneer.parentdir_prefix = project_name + '-'
try:
from Cython.Distutils import build_ext
except ImportError:
has_cython = False
ext_extention = '.c'
else:
has_cython = True
ext_extention = '.pyx'
ext_modules = [Extension("corecalculation_c",
[project_name + \
"/calculation/corecalculation_c" + ext_extention])]
cmdclass = versioneer.get_cmdclass()
if has_cython:
cmdclass.update(build_ext=build_ext)
setup(name = project_name,
version = versioneer.get_version(),
cmdclass = cmdclass,
include_dirs = [np.get_include()],
ext_modules = ext_modules,
author = 'Author Name',
author_email = 'email@address',
url = 'http://github.com/USER/PROJECT/',
download_url = 'http://github.com/USER/PROJECT/',
install_requires = ['numpy', 'scipy', 'matplotlib', 'ipython'],
license = 'GPLv2',
description = ("Oneline description"),
long_description = long_description,
platforms = ('Windows', 'Linux', 'Mac OS X'),
classifiers=['Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Topic :: Scientific/Engineering',
],
packages = [project_name, project_name+'.utils'],
keywords = 'keyword1 keyword2',
)
import numpy
而不遇到麻烦。使用try
语句进行防御性导入和使用 setuptools 的install_requires
可能会为您解决问题。 - celrequires
和install_requires
之间的区别吗? - user2304916