使用 pip install 的异常

Posted

技术标签:

【中文标题】使用 pip install 的异常【英文标题】:Exception using pip install 【发布时间】:2015-10-09 02:51:34 【问题描述】:

我是 python 新手,并试图在我在 DigitalOcean 上使用 Ubuntu 14.04 设置的服务器实例上安装我的 django 项目。当我运行命令sudo pip install requirements.txt 时,它似乎安装了所有要求,但随后产生以下异常:

running build_ext

building '_cffi_backend' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/c

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-2.7/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

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-k7f7bu-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/cffi
Storing debug log for failure in /home/myname/.pip/pip.log

我检查过,我的开发机器和服务器都安装了相同版本的python(2.7.6)

更新 在运行 I'L'I 下面建议的安装后,我取得了一些进展,但又遇到了另一个异常:

running build_ext

building 'gnureadline' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/Modules

creating build/temp.linux-x86_64-2.7/Modules/2.x

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/usr/include/python2.7 -c Modules/2.x/readline.c -o build/temp.linux-x86_64-2.7/Modules/2.x/readline.o

In file included from Modules/2.x/readline.c:31:0:

./readline/readline.h:385:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]

 extern int rl_message ();

 ^

x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/Modules/2.x/readline.o readline/libreadline.a readline/libhistory.a -lncurses -o build/lib.linux-x86_64-2.7/gnureadline.so

/usr/bin/ld: cannot find -lncurses

collect2: error: ld returned 1 exit status

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/gnureadline/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-B2p3jW-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/gnureadline
Storing debug log for failure in /home/juan/.pip/pip.log

【问题讨论】:

可能相关:***.com/questions/31508612/… 【参考方案1】:

您似乎没有安装libffi-dev

sudo apt-get install libffi-dev

应该安装缺少标头的包。

如果这是一个新服务器,那么您也可以选择一次安装一些更常见的开发包:

sudo apt-get install libffi-dev libssl-dev libxml2-dev libxslt1-dev libncurses5-sdev

【讨论】:

谢谢,这有点帮助,但我得到了另一个例外。如果可以,请再次提供帮助。查看更新的问题 看来你还需要安装ncurses:sudo apt-get install libncurses5-dev 谢谢 - 成功了!

以上是关于使用 pip install 的异常的主要内容,如果未能解决你的问题,请参考以下文章

windows python easy_install ,pip. selenium

pip install出错,pip版本不匹配

pip install PIL报错问题解决

python包管理工具pip install详解

python -m pip install --upgrade pip 更新一直报错

python pip install error