简体   繁体   English

如何 pip 安装 cairocffi?

[英]How to pip install cairocffi?

How do I install cairocffi through pip ?如何通过pip安装cairocffi

cairocffi is a CFFI-based drop-in replacement for Pycairo https://github.com/SimonSapin/cairocffi . cairocffi是基于Pycairo https://github.com/SimonSapin/cairocffi替代品。

I'm trying to install it on Ubuntu 14.04:我正在尝试在 Ubuntu 14.04 上安装它:

alvas@ubi:~$ 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/"

I've tried installing with the standard pip command but I get this:我试过使用标准的 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

I've manually checked the permission and I realized that there's no write access permission.我已经手动检查了权限,我意识到没有写访问权限。 Why is that so?为什么呢? And why isn't sudo working to overwrite the permission?为什么 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

When I tried sudo -H pip install cairoffi , I got:当我尝试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

As @MattDMo suggested, i've tried apt-get install libffi but it still didn't work out:正如@MattDMo 所建议的,我已经尝试过apt-get install libffi但它仍然没有解决:

alvas@ubi:~$ sudo apt-get install libffi libffi-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libffi

But there isn't any libffi on the package manager, so i've tried libffi-dev :但是包管理器上没有任何libffi ,所以我尝试了libffi-dev

alvas@ubi:~$ 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) ...

It installs libffi-dev successfully but cairoffi is still not installing:它成功安装了libffi-devcairoffi仍未安装:

alvas@ubi:~$ 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
alvas@ubi:~$ 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

It's right in the error message:它在错误消息中是正确的:

No package 'libffi' found

You'll need to install libffi and libffi-dev through your distro's package manager ( yum , apt-get , whatever) before the pip installation will work.pip安装工作之前,您需要通过发行版的包管理器( yumapt-get等)安装libffilibffi-dev Their names may very slightly from platform to platform.他们的名字可能会因平台而异。

Couldn't get it to work, even with libffi6 libffi-dev installed.即使安装了libffi6 libffi-dev也无法让它工作。 Finally got it working with:终于让它与:

pip3 install -U pip
pip3 install -U setuptools
pip3 install --no-cache-dir cairocffi

--no-cache-dir was the trick, thanks to: https://github.com/Kozea/cairocffi/issues/125#issuecomment-476295293 --no-cache-dir是诀窍,感谢: https : //github.com/Kozea/cairocffi/issues/125#issuecomment-476295293

For me, on Windows 10 using python 3.5.3rc1, pip install cairocffi was failing.对我来说,在使用 python 3.5.3rc1 的 Windows 10 上, pip install cairocffi失败了。 Doing pip install cffi was sufficient to let it succeed.pip install cffi足以让它成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM