2012-01-03 32 views
22

Đây có thể là câu hỏi tiếp theo về số this một.Cài đặt gọn gàng dưới dạng phụ thuộc với công cụ thiết lập

Tôi đang sử dụng setuptools để cài đặt gói của tôi. Là một phụ thuộc tôi đã liệt kê numpy. Tôi đang sử dụng Python2.7 và khi tôi làm

python setup.py install 

với setup.py tập tin này:

from setuptools import setup 

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

tôi kết thúc với thông báo lỗi này:

ImportError: No module named numpy.distutils 

gì tôi cần phải làm để bao gồm numpy làm phụ thuộc và cài đặt nó mà không cần cài đặt python-dev?


Sản lượng hoàn thành của 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 

Trả lời

3

Trừ khi bạn có quyền truy cập vào một phân phối nhị phân (pre-biên soạn/xây dựng) cho numpy, bạn sẽ cần phải có các tiêu đề trăn sẵn vì nó cần chúng để xây dựng gumpy. Đây là lý do tại sao hầu hết các nhà quản lý gói đi kèm với các phiên bản được biên dịch trước của các gói này. Ví dụ: bạn có thể apt-get install python-numpy, liên kết điều đó với virtualenv của bạn và khi bạn cố gắng cài đặt chương trình của mình với install_requires=['numpy'], bạn sẽ thấy rằng chương trình đã được cài đặt.

+1

không có phải là một cách để nói 'setuptools' để xây dựng' numpy' trước khi cài đặt nó? Xây dựng và cài đặt 'numpy' trên các công trình của riêng mình một cách hoàn hảo ... – Woltan

+0

Tôi xin lỗi tôi không làm theo. Từ đầu ra được dán của bạn, nó ** đang cố gắng xây dựng một khối u. –

+0

Phải, nhưng tôi có thể xây dựng và cài đặt 'numpy' tải xuống nó một mình (không phải với' bộ công cụ cài đặt'). Chỉ khi tôi cố gắng để xây dựng và cài đặt nó với 'setuptools' nó bị hỏng. – Woltan

2

Để cài đặt numpy, trình cài đặt sẽ tải xuống gói và biên dịch nó từ nguồn. Tuy nhiên, có một số điều kiện tiên quyết để biên dịch numpy, bạn có thể kiểm tra nó here.

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

lỗi này cho biết rằng ít nhất bạn chưa cài đặt gói python-dev (nếu bạn đang sử dụng ubuntu/debian).

5

Đây là sự cố đã biết, được theo dõi trên numpy/numpy #2434.

Tôi đã tìm thấy giải pháp cho việc này: thêm numpy vào setup_requires. Có nó trong cả hai setup_requiresinstall_requires dường như hoạt động tốt với phiên bản mới nhất của setuptools.

Vì vậy, setup.py của bạn sẽ giống như

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

Thêm numpy vào 'setup_requires' là không đủ. Tôi cũng phải chạy 'python setup.py unstall' hai lần để cài đặt thành công, xem thêm http://stackoverflow.com/questions/21605927/why-doesnt-setup-requires-work-properly-for-numpy – asmaier

Các vấn đề liên quan