python - pip安装python-lzo时找不到文件报错

标签 python macos-sierra lzo

我正在尝试在 mac OS Sierra 上安装 python-lzo。我已经使用 brew 安装了 c lzo 库:

brew update
brew install lzo

然后我尝试使用虚拟环境和 pip 安装 python-lzo:

$ virtualenv ./env
$ . ./env/bin/activate
$ pip install python-lzo

这给了我以下输出:

Collecting python-lzo
  Using cached python-lzo-1.11.tar.gz
Building wheels for collected packages: python-lzo
  Running setup.py bdist_wheel for python-lzo: started
  Running setup.py bdist_wheel for python-lzo: finished with status 'error'
  Complete output from command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/pip-build-wDRYjx/python-lzo/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/tmp_ueOY4pip-wheel- --python-tag cp27:
  /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:251: UserWarning: 'licence' distribution option is deprecated; use 'license'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_ext
  building 'lzo' extension
  creating build
  creating build/temp.macosx-10.11-x86_64-2.7
  clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/lzo -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lzomodule.c -o build/temp.macosx-10.11-x86_64-2.7/lzomodule.o
  lzomodule.c:35:10: fatal error: 'lzo1x.h' file not found
  #include <lzo1x.h>
           ^
  1 error generated.
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  Running setup.py clean for python-lzo
Failed to build python-lzo
Installing collected packages: python-lzo
  Running setup.py install for python-lzo: started
    Running setup.py install for python-lzo: finished with status 'error'
    Complete output from command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/pip-build-wDRYjx/python-lzo/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/pip-8RUWxo-record/install-record.txt --single-version-externally-managed --compile:
    /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:251: UserWarning: 'licence' distribution option is deprecated; use 'license'
      warnings.warn(msg)
    running install
    running build
    running build_ext
    building 'lzo' extension
    creating build
    creating build/temp.macosx-10.11-x86_64-2.7
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/lzo -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lzomodule.c -o build/temp.macosx-10.11-x86_64-2.7/lzomodule.o
    lzomodule.c:35:10: fatal error: 'lzo1x.h' file not found
    #include <lzo1x.h>
             ^
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------

lzo1x.h 文件确实存在于此处:/usr/local/opt/lzo/include/lzo/ 或使用 brew命令:

$ ls $(brew --prefix lzo)/include/lzo/

然后我尝试设置CFLAGS环境变量,但仍然有同样的错误:

$ export EXTRA_CFLAGS=-I/usr/local/opt/lzo/include && export EXTRA_CXXFLAGS=-I/usr/local/opt/lzo/include && export EXTRA_LDFLAGS=-L/usr/local/opt/lzo/lib && pip install

绝望中:

$ export EXTRA_CFLAGS=-I/usr/local/opt/lzo/include/lzo && export EXTRA_CXXFLAGS=-I/usr/local/opt/lzo/include/lzo && export EXTRA_LDFLAGS=-L/usr/local/opt/lzo/lib && pip install python-lzo

还是一样的错误信息,有什么想法吗?

-- 已更新--
还尝试将变量直接传递到 pip:

pip install --global-option='build_ext' --global-option='-I/usr/local/opt' --global-option='-I/usr/local/opt/lzo/include/lzo' --global-option='-L/usr/local/opt/lzo/lib' python-lzo

这次我得到一个稍微不同的错误:

  cmdoptions.check_install_build_global(options)
Collecting python-lzo
  Using cached python-lzo-1.11.tar.gz
Skipping bdist_wheel for python-lzo, due to binaries being disabled for it.
Installing collected packages: python-lzo
  Running setup.py install for python-lzo ... error
    Complete output from command /Users/myuser/dir/devel/lzo_example/env/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/pip-build-14vN3V/python-lzo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" build_ext -I/usr/local/opt -I/usr/local/opt/lzo/include/lzo -L/usr/local/opt/lzo/lib install --record /var/folders/38/v_r4bjvx7dz626x16nh6jcn00000gn/T/pip-Gq5pjs-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/emson/Dropbox/devel/aws/coursenut_bigdata/lzo_example/env/bin/../include/site/python2.7/python-lzo:
    /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:251: UserWarning: 'licence' distribution option is deprecated; use 'license'
      warnings.warn(msg)
    running build_ext
    building 'lzo' extension
    creating build
    creating build/temp.macosx-10.11-x86_64-2.7
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/lzo -I/usr/local/opt/lzo/include/lzo -I/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lzomodule.c -o build/temp.macosx-10.11-x86_64-2.7/lzomodule.o
    In file included from lzomodule.c:35:
    /usr/local/opt/lzo/include/lzo/lzo1x.h:33:10: fatal error: 'lzo/lzoconf.h' file not found
    #include <lzo/lzoconf.h>
             ^
    1 error generated.
    error: command 'clang' failed with exit status 1

非常感谢

-- 成功 ---

非常感谢@daphtdazz,您的解决方案(见下文)奏效了! 我稍微修改了它以使用 brew --cellar 命令获取 lzo 文件的位置:

导出 C_INCLUDE_PATH=$(brew --cellar lzo)/2.09/include/lzo:$(brew --cellar lzo)/2.09/include/ 导出 LIBRARY_PATH=/usr/local/lib pip 安装 python-lzo

最佳答案

我得到了和你一样的结果,最终这对我有用:

export C_INCLUDE_PATH=/usr/local/Cellar/lzo/2.09/include/lzo:/usr/local/Cellar/lzo/2.09/include 
export LIBRARY_PATH=/usr/local/lib 
pip install python-lzo

(显然,您可能需要根据安装的 lzo brew 发行版版本进行调整。)

这回答了我的问题,但我真的不明白为什么这些配置不正确......

虽然我也安装了 Xcode 开发人员工具,但我认为它们之前与 brewpip 有冲突,所以也许就是这样。我会继续看,如果我解决了,我会更新这个答案。

编辑

看看 setup.py python-lzo 的文件似乎有点奇怪,特别是我担心在 Windows 上添加了两个包含路径,这表明 lzo 源分配不是很好安排。但是似乎没有设计好的方法可以通过 brew 安装在 macOS 上实现这一点,所以我认为它的 include 部分至少最好用额外的环境变量来解决。

关于python - pip安装python-lzo时找不到文件报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40424097/

相关文章:

python - 读取每个文件后如何写入新行?

python - Django RateLimit 403 页面未被替换

Python + SQLite : Unable to determine cause of incorrect number of bindings supplied error

python - 在 MacOS Sierra 中的 Apache 上执行 python 脚本

php - 在 PHP 中解压缩 LZO 流

python - 使用 mrjob 处理 LZO 序列文件

python - 队列中的所有任务已完成,但程序未继续

swift - 验证 NSTouchBar 项目的最佳实用方法

centos - 如何在 OS X 和 Linux 上使用 unison?由于 ocaml 版本导致的 fatal error

java - 如何解压缩 lzo_deflate 文件?