问题描述
在我的Python 2.7项目中,我需要安装ta-lib库。 在目标环境上,我没有root或sudo权限,因此Python应用程序在虚拟环境中运行。
出于未知原因,当libta_lib.so驻留在用户目录结构(而不??是系统的/ usr文件夹)中时,使用pip安装ta-lib库失败。
我做了什么:
我正在使用Python 2.7创建新的虚拟环境:
ec2-user:~/environment $ python -V
Python 2.7.14
ec2-user:~/environment $ virtualenv -p /usr/bin/python27 my_env
Running virtualenv with interpreter /usr/bin/python27
New python executable in /home/ec2-user/environment/my_env/bin/python27
Also creating executable in /home/ec2-user/environment/my_env/bin/python
Installing setuptools, pip, wheel...done.
ec2-user:~/environment $ source my_env/bin/activate
(my_env) ec2-user:~/environment $
在my_env中,我下载并解压缩最新的 。 我使用前缀标志将安装路径配置为在虚拟环境中。
(my_env) ec2-user:~/environment/my_env $ ./configure --prefix=/home/ec2-user/environment/my_env
(my_env) ec2-user:~/environment/my_env $ make
(my_env) ec2-user:~/environment/my_env $ make install
配置,制作和安装工作正常。 最后,系统告诉我一些东西:
Libraries have been installed in:
/home/ec2-user/environment/my_env/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
[...]
所以我将/ home / ec2-user / environment / my_env / lib添加到$ LD_LIBRARY_PATH和$ LD_RUN_PATH。 到目前为止,一切看起来都很好,但是当我
(my_env) ec2-user:~/environment/my_env $ pip install ta-lib
Collecting ta-lib
Using cached https://files.pythonhosted.org/packages/[...]/
TA-Lib-0.4.17.tar.gz
Requirement already satisfied: numpy in ./lib/python2.7/dist-packages
(from ta-lib) (1.15.1)
Building wheels for collected packages: ta-lib
Running setup.py bdist_wheel for ta-lib ... error
Complete output from command /home/ec2-user/environment/my_env/bin/python27
-u -c "import setuptools, tokenize;__file__='/tmp/pip-install-MD3Ds7/ta-
lib/setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code,
__file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-dtdhyb --python-tag cp27:
/tmp/pip-install-MD3Ds7/ta-lib/setup.py:79: UserWarning: Cannot find ta-lib
library, installation may fail.
warnings.warn('Cannot find ta-lib library, installation may fail.')
还有...
creating build/temp.linux-x86_64-2.7/talib
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/ec2-user/environment/my_env/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/usr/include/python2.7 -c talib/_ta_lib.c -o build/temp.linux-x86_64-2.7/talib/_ta_lib.o
talib/_ta_lib.c:526:28: fatal error: ta-lib/ta_defs.h: No such file or directory
#include "ta-lib/ta_defs.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/home/ec2-user/environment/my_env/bin/python27 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-MD3Ds7/ta-lib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-YqZ5hO/install-record.txt --single-version-externally-managed --compile --install-headers /home/ec2-user/environment/my_env/include/site/python2.7/ta-lib" failed with error code 1 in /tmp/pip-install-MD3Ds7/ta-lib/
[...]
我还尝试将“ / home / ec2-user / environment / my_env / lib”添加到$ PATH,但是结果是相同的。
为什么不能点子找到位于虚拟环境内lib文件夹中的librar?
当我将ta-lib二进制文件安装到默认的/ usr / lib文件夹中时(当然使用sudo),pip install ta-lib将找到它并进行安装。 不幸的是,这不是目标系统的选项。
我做错什么了吗,还是pip忽略了虚拟envrionemt中的文件夹和路径变量?
问候,啤酒
1楼
pip install
python绑定时,您需要传递已安装标头和共享对象的自定义位置:
$ CPPFLAGS='-I/home/ec2-user/environment/my_env/include' \
LDFLAGS='-L/home/ec2-user/environment/my_env/lib' pip install ta-lib