Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing numpy as a dependency with setuptools

This might be a follow up question of this one.

I am using setuptools to install a package of mine. As a dependency I have listed numpy. I am using Python2.7 and when I do

python setup.py install

with this setup.py file:

from setuptools import setup

setup(name = "test_pack", install_requires = ["numpy"])

I end up with this error message:

ImportError: No module named numpy.distutils

What do I need to do in order to include numpy as a dependency and install it without having python-dev installed?


The complete output of python setup.py install:

running install
running bdist_egg
running egg_info
writing requirements to test_pack.egg-info/requires.txt
writing test_pack.egg-info/PKG-INFO
writing top-level names to test_pack.egg-info/top_level.txt
writing dependency_links to test_pack.egg-info/dependency_links.txt
reading manifest file 'test_pack.egg-info/SOURCES.txt'
writing manifest file 'test_pack.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/test_pack
copying build/lib/test_pack/__init__.py -> build/bdist.linux-x86_64/egg/test_pack
copying build/lib/test_pack/mod.py -> build/bdist.linux-x86_64/egg/test_pack
byte-compiling build/bdist.linux-x86_64/egg/test_pack/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/test_pack/mod.py to mod.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying test_pack.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying test_pack.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying test_pack.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying test_pack.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying test_pack.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/test_pack-0.0.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing test_pack-0.0.0-py2.7.egg
Copying test_pack-0.0.0-py2.7.egg to /home/woltan/local/lib/python2.7/site-packages
Adding test-pack 0.0.0 to easy-install.pth file

Installed /home/woltan/local/lib/python2.7/site-packages/test_pack-0.0.0-py2.7.egg
Processing dependencies for test-pack==0.0.0
Searching for numpy
Reading http://pypi.python.org/simple/numpy/
Reading http://numpy.scipy.org
Reading http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103
Reading http://numeric.scipy.org
Best match: numpy 1.6.1
Downloading http://pypi.python.org/packages/source/n/numpy/numpy-1.6.1.zip#md5=462c22b8eb221c78ddd51de98fbb5979
Processing numpy-1.6.1.zip
Running numpy-1.6.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-AoFmdV/numpy-1.6.1/egg-dist-tmp-JH1j2R
non-existing path in 'numpy/distutils': 'site.cfg'
Could not locate executable g77
Found executable /opt/solstudio12.2/bin/f77
gnu: no Fortran 90 compiler found
gnu: no Fortran 90 compiler found
Found executable /opt/intel/Compiler/11.1/073/bin/intel64/ifort
Could not locate executable lf95
Could not locate executable pgf90
Could not locate executable pgf77
Found executable /opt/solstudio12.2/bin/f90
Found executable /opt/solstudio12.2/bin/f95
Could not locate executable fort
_configtest.c:1: warning: conflicting types for built-in function ‘exp’
_configtest.o: In function `main':
/tmp/easy_install-AoFmdV/numpy-1.6.1/_configtest.c:6: undefined reference to `exp'
collect2: ld returned 1 exit status
_configtest.c:1: warning: conflicting types for built-in function ‘exp’
_configtest.c:1:20: error: Python.h: No such file or directory
_configtest.o: In function `main':
/tmp/easy_install-AoFmdV/numpy-1.6.1/_configtest.c:6: undefined reference to `exp'
collect2: ld returned 1 exit status
_configtest.c:1:20: error: Python.h: No such file or directory
like image 553
Woltan Avatar asked Jan 03 '12 10:01

Woltan


People also ask

How do I install packages on setuptools?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

Does pip depend on setuptools?

In Fedora, our pip package Recommends setuptools. Practically that means: Majority of users who install pip will get setuptools by default. Users can explicitly uninstall setuptools after installing pip or exclude setuptools when installing pip.

Can you pip install NumPy?

NumPy can be installed with conda , with pip , with a package manager on macOS and Linux, or from source.


3 Answers

This is a known issue, tracked on numpy/numpy #2434.

I found a workaround for this: add numpy to setup_requires. Having it in both setup_requires and install_requires seems to work fine with the most recent version of setuptools.

So, your setup.py should look something like

setup(     # Your setup specific stuff here     setup_requires=["numpy"],  # Just numpy here     install_requires=["numpy"],  # Add any of your other dependencies here ) 
like image 80
tbekolay Avatar answered Oct 05 '22 22:10

tbekolay


Unless you have access to a binary distribution (pre-compiled/built) for numpy, you'll have to have the python headers available as it needs them to build numpy. This is why most package managers come with pre-compiled versions of these packages. For example you can apt-get install python-numpy, link that into your virtualenv, and when you try to install your program with install_requires=['numpy'] it should see that it's already installed.

like image 42
Michael Merickel Avatar answered Oct 05 '22 23:10

Michael Merickel


To install numpy the setuptools will download the package and compile it from source. However, there are some prerequisites to compile numpy, you can check it here.

_configtest.c:1:20: error: Python.h: No such file or directory

this error indicates that at least you do not have python-dev package installed(if you are using ubuntu/debian).

like image 45
Chunliang Lyu Avatar answered Oct 05 '22 22:10

Chunliang Lyu