2012-01-03 86 views
22

這可能是後續問題this之一。安裝numpy作爲與setuptools的依賴關係

我使用的是setuptools來安裝我的一個軟件包。作爲一個依賴我已經列出了numpy。我使用Python2.7當我做

python setup.py install 

與此setup.py文件:

from setuptools import setup 

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

我結束了此錯誤消息:

ImportError: No module named numpy.distutils 

什麼我需要做的爲了將numpy作爲依賴包並安裝它,而不安裝python-dev


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 

回答

3

除非你有機會獲得一個二進制分發(預編譯的,/內置)爲numpy的,你必須有可用的,因爲它的蟒蛇頭需要他們建立numpy。這就是爲什麼大多數軟件包管理器都帶有這些軟件包的預編譯版本。例如,您可以將apt-get install python-numpy,鏈接到您的virtualenv,並且當您嘗試使用install_requires=['numpy']安裝程序時,它應該會看到它已經安裝。

+1

難道沒有辦法告訴'setuptools'安裝前建立'numpy'?建立和安裝'numpy'完美的自己的作品... – Woltan 2012-01-03 11:02:30

+0

我很抱歉,我不關注。從你的粘貼輸出它**是**試圖建立numpy。 – 2012-01-03 11:03:39

+0

沒錯,但我可以自己編譯並安裝'numpy'下載它(而不是'setuptools')。只有當我嘗試用'setuptools'構建並安裝它時,它纔會中斷。 – Woltan 2012-01-03 11:06:36

2

要安裝numpy,setuptools將下載包並從源代碼進行編譯。不過,編譯numpy有一些先決條件,你可以檢查它here

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

此錯誤表明至少您沒有安裝python-dev軟件包(如果您使用的是Ubuntu/Debian)。

5

這是一個已知問題,跟蹤在numpy/numpy #2434

我找到了解決方法:將numpy添加到setup_requires。在setup_requiresinstall_requires中使用它似乎與setuptools的最新版本正常工作。

所以,你setup.py應該是這個樣子

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

將numpy添加到'setup_requires'是不夠的。我還必須運行'python setup.py unstall'兩次才能成功安裝numpy,另請參閱http://stackoverflow.com/questions/21605927/why-doesnt-setup-requires-work-properly-for-numpy – asmaier 2015-04-08 15:45:19