设置工具,核心区,install_requires和f2py扩展名

2024-10-01 17:24:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直致力于创建一个python包,其中包含一些fortran代码,我想在numpy中使用f2py合并这些代码。目标是将其上载到PyPI,以便用户可以使用pip进行安装。我做了一些研究,发现setuptools和numpy.distutils.core有我想要的功能(我想)。包裹的结构是这样的

rabacus  
--setup.py  
--README.txt  
--MANIFEST.in    
--rabacus  
----f2py  
----python_mod1  
----python_mod2  
----python_mod3 

fortran代码在f2py目录下。我的包需要numpy和另一个python包quantity,这两个包都在PyPI中。我已经在setup函数中用install\u requires关键字指出了这一点。我的测试周期是这样的

注册并将包上载到PyPI

^{pr2}$

创建没有系统包的虚拟环境

virtualenv --no-site-packages venv

移入虚拟环境并尝试使用pip进行安装

cd venv/bin  
./pip install rabacus

我希望它能检测到未满足的需求(数量和数量),下载它们,然后继续安装我的软件包。我不知道应该调用哪个设置函数(setuptools中的函数还是setuptools中的函数)核心区). 似乎有一个安装需要,一个有扩展模块。到目前为止,当我在虚拟环境中执行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作为一个需求并在设置.py脚本?在

我的设置.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],

)

Tags: pipinpycoreimportnumpyvenvsetup

热门问题