2012-01-03 14 views
22

Questa potrebbe essere una domanda successiva di this.Installazione di numpy come dipendenza con setuptools

Sto usando setuptools per installare un mio pacchetto. Come dipendenza ho elencato numpy. Sto usando Python2.7 e quando lo faccio

python setup.py install 

con questo setup.py lima:

from setuptools import setup 

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

io alla fine con questo messaggio di errore:

ImportError: No module named numpy.distutils 

Di cosa ho bisogno di fare per includere numpy come dipendenza e installarlo senza aver installato python-dev?


L'uscita completa di 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 

risposta

3

A meno che non si ha accesso a una distribuzione binaria (pre-compilato/built) per NumPy, dovrete avere le intestazioni pitone disponibili come li ha bisogno di costruire numpy. Questo è il motivo per cui la maggior parte dei gestori di pacchetti ha versioni precompilate di questi pacchetti. Ad esempio puoi apt-get install python-numpy, collegarlo al tuo virtualenv e quando provi ad installare il tuo programma con install_requires=['numpy'] dovrebbe vedere che è già installato.

+1

non c'è un modo per dire 'setuptools' di costruire' numpy' prima di installarlo? Costruire e installare 'numpy' sulle proprie opere perfettamente ... – Woltan

+0

Mi dispiace non seguire. Dal tuo output incollato ** è ** il tentativo di creare numpy. –

+0

Esatto, ma sono in grado di creare e installare 'numpy' scaricandolo da solo (non con' setuptools'). Solo se provo a creare e installare con 'setuptools', si rompe. – Woltan

2

Per installare numpy, setuptools scaricherà il pacchetto e lo compilerà dal sorgente. Tuttavia, ci sono alcuni prerequisiti per compilare numpy, è possibile verificarlo here.

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

Questo errore indica che almeno non devi pacchetto python-dev installato (se si utilizza Ubuntu/Debian).

5

Questo è un problema noto, monitorato su numpy/numpy #2434.

Ho trovato una soluzione per questo: aggiungi numpy a setup_requires. Averlo in entrambi setup_requires e install_requires sembra funzionare bene con la versione più recente di setuptools.

Così, il vostro setup.py dovrebbe essere simile a

setup(
    # Your setup specific stuff here 
    setup_requires=["numpy"], # Just numpy here 
    install_requires=["numpy"], # Add any of your other dependencies here 
) 
+0

L'aggiunta di numpy a 'setup_requires' non è stata sufficiente. Ho anche dovuto eseguire 'python setup.py unstall' due volte per installare numpy correttamente, vedi anche http://stackoverflow.com/questions/21605927/why-doesnt-setup-requires-work-properly-for-numpy – asmaier

Problemi correlati