6

I've been working on creating a python package that contains some fortran code which I'd like to incorporate using f2py in numpy. The goal is to upload it to PyPI so that users can install using pip. I've done some research and figured out that setuptools and numpy.distutils.core have the functionality I want (I think). The package is structured like this,

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

and I have the fortran code in the directory f2py. My package requires numpy and another python package called quantities both of which are in PyPI. I've indicated this with the install_requires keyword to the setup function. My testing cycle goes like this,

register and upload package to PyPI

python setup.py register sdist upload

create a virtual environment with no system packages

virtualenv --no-site-packages venv

move into the virtual environment and attempt to install using pip

cd venv/bin  
./pip install rabacus

I'd like it to detect the unmet requirements (numpy and quantities), download them and then proceed with my package installation. I'm confused about which setup function I should call (the one from setuptools or the one from numpy.distutils.core). It seems that one has install_requires and one has ext_modules. So far when I execute the pip command in the virtual environment I get an error complaining that numpy cant be 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

Is it possible to have numpy as a requirement and use numpy in the setup.py script?

My setup.py looks like this,

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

)
  • 2
    looks like there is not a standard solution ... http://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py –  Jan 31 '14 at 07:03

0 Answers0