2012-01-06 35 views
7

我試圖在Virtualenv中安裝Fabric,但出現錯誤。我是usinh Python 2.7.2+可以在Virtualenv中安裝Fabric(Python)嗎?獲取錯誤

src/MD2.c:31:20: fatal error: Python.h: No such file or directory 

compilation terminated. 

error: command 'gcc' failed with exit status 1 

---------------------------------------- 
Command /home/andre/python_virtualenv/bin/python -c "import setuptools;__file__='/home/andre/python_virtualenv/build/pycrypto/setup.py'; exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-YGuAIj-record/install-record.txt --install-headers /home/andre/python_virtualenv/include/site/python2.7 failed with error code 1 
Storing complete log in /home/andre/.pip/pip.log 

這裏有什麼問題的一些線索?

最好的問候,

回答

15

如果使用Debian的Linux的味,您需要安裝python2.x-dev軟件包

命令和apt-get安裝python2.7-dev的

這是因爲一些Python庫只是結合需要在使用之前編譯的C庫,需要頭文件來完成。

Fabric使用Paramiko通過SSH連接,其中包含此類綁定。

頭文件通常位於packagename-dev(debian)或packagename-develop(redhat)的包中。在這裏,我們看到Python 2.7的python.h頭文件缺失,所以我們安裝python2.7-dev。因爲它是在系統級別安裝的,所以對於所有的虛擬環境,您只需要執行一次該操作。

如果您使用與其他C產品相關的庫(例如mysql libs,它需要mysql頭文件),則會出現相同的問題。

+1

@ e-satis非常感謝你爲這個偉大的加法! – vorushin 2012-01-06 14:26:02

+1

你在我做之前就回答了它,所以沒有用的做一個重複的:-) – 2012-01-06 16:28:43

1

你需要讓GCC知道Python的include路徑和lib路徑。

首先你需要找到你的Python的包含&的lib路徑。

例如:

/home/me/soft/include 

/home/me/soft/lib 

然後導出以下VAR在bash

export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/me/soft/include 

而且

export LD_LIBRARY_PATH=$C_INCLUDE_PATH:/home/me/soft/lib 

這不是唯一的方法,但應該爲你工作。

相關問題