Setuptools, numpy.distutils.core, install_requires and the f2py extension

I was working on creating a python package that contains some fortran code that I would like to include with f2py in numpy. The goal is to download it in PyPI so that users can install using pip. I did some research and found out that setuptools and numpy.distutils.core have the functionality that I want (I think). The package is structured as follows:

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

and I have the fortran code in the f2py directory. My package requires numpy and another python package called values, both of which are in PyPI. I pointed this out with the install_requires keyword for the configuration function. My testing cycle is as follows:

register and download the package in PyPI

python setup.py register sdist upload

virtualenv --no-site-packages venv

pip

cd venv/bin  
./pip install rabacus

, ( ), , . , ( setuptools numpy.distutils.core). , install_requires, ext_modules. pip , , , numpy can not found

 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 numpy setup.py script?

My 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],

)
+4

Source: https://habr.com/ru/post/1524647/


All Articles