我一直在创建一个python包,其中包含一些我想在numpy中使用f2py合并的fortran代码。目标是将其上传到PyPI,以便用户可以使用pip进行安装。我做了一些研究,发现setuptools和numpy.distutils.core具有我想要的功能(我认为)。包的结构如下,
rabacus
--setup.py
--README.txt
--MANIFEST.in
--rabacus
----f2py
----python_mod1
----python_mod2
----python_mod3
我在目录f2py中有fortran代码。我的包需要numpy和另一个名为quantity的python包,这两个包都在PyPI中。我已经使用install_requires关键字向setup函数指出了这一点。我的测试周期是这样的,
注册并将包上传到PyPI
python setup.py register sdist upload
创建一个没有系统包的虚拟环境
virtualenv --no-site-packages venv
进入虚拟环境并尝试使用pip进行安装
cd venv/bin
./pip install rabacus
我希望它检测未满足的要求(numpy和数量),下载它们然后继续我的软件包安装。我很困惑我应该调用哪个设置函数(来自setuptools的那个或来自numpy.distutils.core的那个)。似乎有一个有install_requires,一个有ext_modules。到目前为止,当我在虚拟环境中执行pip命令时,我收到一个错误,抱怨找不到numpy
Downloading/unpacking rabacus
Downloading rabacus-0.9.0.tar.gz (1.7MB): 1.7MB downloaded
Running setup.py egg_info for package rabacus
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/galtay/bitbucket/rabacus/venv/build/rabacus/setup.py", line 3, in <module>
import numpy.distutils.core
ImportError: No module named numpy.distutils.core
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/galtay/bitbucket/rabacus/venv/build/rabacus/setup.py", line 3, in <module>
import numpy.distutils.core
ImportError: No module named numpy.distutils.core
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/galtay/bitbucket/rabacus/venv/build/rabacus
Storing complete log in /home/galtay/.pip/pip.log
是否可以将numpy作为一项要求并在setup.py脚本中使用numpy?
我的setup.py看起来像这样,
import os
import setuptools
import numpy.distutils.core
# setup fortran 90 extension
#---------------------------------------------------------------------------
f90_fnames = ['types.f90', 'utils.f90', 'physical_constants.f90',
'hui_gnedin_97.f90', 'hm12.f90', 'chem_cool_rates.f90',
'ion_solver.f90', 'verner_96.f90', 'photo_xsections.f90',
'spectra.f90', 'source_point.f90', 'source_plane.f90',
'source_background.f90', 'iliev_sphere.f90', 'slab_plane.f90']
f90_paths = []
for fname in f90_fnames:
f90_paths.append( 'rabacus/f2py/' + fname )
ext1 = numpy.distutils.core.Extension(
name = 'rabacus_fc',
sources = f90_paths
)
# write short description
#--------------------------------------------------------------------------
description = 'Calculates analytic cosmological radiative transfer ' + \
'solutions in simplified geometries.'
# puts the contents of the README file in the variable long_description
#--------------------------------------------------------------------------
with open('README.txt') as file:
long_description = '\n\n ' + file.read()
# call setup
#--------------------------------------------------------------------------
#setuptools.setup(
numpy.distutils.core.setup(
install_requires = ['quantities', 'numpy'],
name = 'rabacus',
version = '0.9.0',
description = description,
long_description = long_description,
url = 'https://bitbucket.org/galtay/rabacus',
download_url = 'https://pypi.python.org/pypi/rabacus',
license = 'GPL v3',
platforms = 'linux',
author = 'Gabriel Altay',
author_email = 'gabriel.altay@gmail.com',
classifiers = [
"Programming Language :: Python",
"Programming Language :: Fortran",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX :: Linux",
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Scientific/Engineering :: Physics",
"Intended Audience :: Science/Research",
"Development Status :: 4 - Beta",
"Topic :: Education",
"Natural Language :: English",
],
packages = setuptools.find_packages(),
package_data = {'': ['*.f90']},
include_package_data = True,
ext_modules = [ext1],
)