2015-04-13 175 views
9

如何安裝cairocffipip如何pip安裝cairocffi?

cairocffi是基於CFFI的嵌入式替代品Pycairohttps://github.com/SimonSapin/cairocffi

我試圖在Ubuntu 14.04安裝:

[email protected]:~$ cat /etc/*-release 
DISTRIB_ID=Ubuntu 
DISTRIB_RELEASE=14.04 
DISTRIB_CODENAME=trusty 
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS" 
NAME="Ubuntu" 
VERSION="14.04.2 LTS, Trusty Tahr" 
ID=ubuntu 
ID_LIKE=debian 
PRETTY_NAME="Ubuntu 14.04.2 LTS" 
VERSION_ID="14.04" 
HOME_URL="http://www.ubuntu.com/" 
SUPPORT_URL="http://help.ubuntu.com/" 
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" 

我試着用標準PIP命令安裝,但我得到這個:

$ sudo pip install cairocffi 
The directory '/home/alvas/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
The directory '/home/alvas/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
The directory '/home/alvas/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
Collecting cairocffi 
    Downloading cairocffi-0.6.tar.gz (75kB) 
    100% |████████████████████████████████| 77kB 34kB/s 
Collecting cffi>=0.6 (from cairocffi) 
    Downloading cffi-0.9.2.tar.gz (209kB) 
    100% |████████████████████████████████| 212kB 97kB/s 
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python3.4/dist-packages (from cffi>=0.6->cairocffi) 
Installing collected packages: cffi, cairocffi 
    Running setup.py install for cffi 
    Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-d3kjzf__/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ll323a3c-record/install-record.txt --single-version-externally-managed --compile: 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    running install 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-3.4 
    creating build/lib.linux-x86_64-3.4/cffi 
    copying cffi/commontypes.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/lock.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/api.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/verifier.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/__init__.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/cparser.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/gc_weakref.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/model.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.4/cffi 
    running build_ext 
    building '_cffi_backend' extension 
    creating build/temp.linux-x86_64-3.4 
    creating build/temp.linux-x86_64-3.4/c 
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.4/c/_cffi_backend.o 
    c/_cffi_backend.c:13:17: fatal error: ffi.h: No such file or directory 
    #include <ffi.h> 
        ^
    compilation terminated. 
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 

    ---------------------------------------- 
    Command "/usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-d3kjzf__/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ll323a3c-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-d3kjzf__/cffi 

我手動檢查許可,我意識到沒有寫訪問權限。 這是爲什麼?爲什麼sudo不能覆蓋權限呢?

$ ls -la .cache/pip/log/ 
total 60 
drwxrwxr-x 2 alvas alvas 4096 Feb 3 10:51 . 
drwx------ 4 alvas alvas 4096 Apr 12 23:16 .. 
-rw-rw-r-- 1 alvas alvas 49961 Apr 12 23:18 debug.log 

當我試圖sudo -H pip install cairoffi,我得到:

sudo -H pip install cairocffi 
Collecting cairocffi 
    Using cached cairocffi-0.6.tar.gz 
Collecting cffi>=0.6 (from cairocffi) 
    Downloading cffi-0.9.2.tar.gz (209kB) 
    100% |████████████████████████████████| 212kB 29kB/s 
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python3.4/dist-packages (from cffi>=0.6->cairocffi) 
Installing collected packages: cffi, cairocffi 
    Running setup.py install for cffi 
    Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-2sv6pbsp/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-xk4kkjrj-record/install-record.txt --single-version-externally-managed --compile: 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    Package libffi was not found in the pkg-config search path. 
    Perhaps you should add the directory containing `libffi.pc' 
    to the PKG_CONFIG_PATH environment variable 
    No package 'libffi' found 
    running install 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-3.4 
    creating build/lib.linux-x86_64-3.4/cffi 
    copying cffi/commontypes.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/lock.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/api.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/verifier.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/__init__.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/cparser.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/gc_weakref.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/model.py -> build/lib.linux-x86_64-3.4/cffi 
    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.4/cffi 
    running build_ext 
    building '_cffi_backend' extension 
    creating build/temp.linux-x86_64-3.4 
    creating build/temp.linux-x86_64-3.4/c 
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.4/c/_cffi_backend.o 
    c/_cffi_backend.c:13:17: fatal error: ffi.h: No such file or directory 
    #include <ffi.h> 
        ^
    compilation terminated. 
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 

    ---------------------------------------- 
    Command "/usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-2sv6pbsp/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-xk4kkjrj-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-2sv6pbsp/cffi 

由於@MattDMo的建議,我已經試過apt-get install libffi但它仍然沒有解決:

[email protected]:~$ sudo apt-get install libffi libffi-dev 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
E: Unable to locate package libffi 

但包管理器上沒有任何libffi,所以我試過libffi-dev

[email protected]:~$ sudo apt-get install libffi-dev 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
The following NEW packages will be installed: 
    libffi-dev 
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded. 
Need to get 99.8 kB of archives. 
After this operation, 323 kB of additional disk space will be used. 
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libffi-dev amd64 3.1~rc1+r3.0.13-12 [99.8 kB] 
Fetched 99.8 kB in 1s (76.3 kB/s)  
Selecting previously unselected package libffi-dev:amd64. 
(Reading database ... 492855 files and directories currently installed.) 
Preparing to unpack .../libffi-dev_3.1~rc1+r3.0.13-12_amd64.deb ... 
Unpacking libffi-dev:amd64 (3.1~rc1+r3.0.13-12) ... 
Processing triggers for man-db (2.6.7.1-1ubuntu1) ... 
Processing triggers for doc-base (0.10.5) ... 
Processing 1 added doc-base file... 
Processing triggers for install-info (5.2.0.dfsg.1-2) ... 
Setting up libffi-dev:amd64 (3.1~rc1+r3.0.13-12) ... 

它安裝libffi-dev成功,但cairoffi仍未安裝:

[email protected]:~$ sudo -H pip install cairoffi 
Collecting cairoffi 
    Could not find a version that satisfies the requirement cairoffi (from versions:) 
    No matching distribution found for cairoffi 
[email protected]:~$ sudo -H pip3 install cairoffi 
Collecting cairoffi 
    Could not find a version that satisfies the requirement cairoffi (from versions:) 
    No matching distribution found for cairoffi 
+0

正如我所說的,你需要使用你的Linux發行包管理器('yum','apt-get',無論)來安裝系統包'libffi'和'libffi-dev'。對不起,如果不是很清楚。 – MattDMo

+0

此外,下次您有關於答案的問題或疑問時,您是否可以在答案下面發表評論,而不僅僅是編輯問題,即使它只是指向編輯?我只看到這個,因爲我不小心將標籤打開。評論會向作者發送通知,以及您可能會提及的任何人。 – MattDMo

回答

13

這是正確的錯誤消息:

No package 'libffi' found 

您需要安裝libffilibffi-dev通過您的發行包管理器(yumapt-get,無論)在安裝pip之前都會起作用。他們的名字可能會從平臺到平臺很小。

+0

@alvas你使用什麼發行版和版本? – MattDMo

+0

這是Ubuntu 14.04 – alvas

+7

在Ubuntu上,軟件包是['libffi6'](http://packages.ubuntu.com/trusty/libffi6)和[''libffi-dev']](http://packages.ubuntu.com/trusty/libffi-dev的)。運行'sudo apt-get install libffi6 libffi-dev'應該可以正常工作... – MattDMo

5

對我而言,在Windows 10上使用python 3.5.3rc1,pip install cairocffi失敗。做pip install cffi足以讓它成功。

+1

非常感謝! – Nonsingular