指定python版本时pip和virtualenv的问题

时间:2014-09-15 08:39:06

标签: python python-2.7 pip virtualenv

我正在使用 virtualenv (1.11.6)来管理我的python项目,我创建了一个新的但是我注意到它使用了旧的python版本(2.7.2而不是2.7.8) ),所以我使用-p选项重新创建了virtualenv:

virtualenv -p /opt/local/bin/python ENV

现在项目使用的是python 2.7.8,但如果我尝试使用 pip 1.5.6安装任何python库(例如 scrapy ),我会得到

  

命令python setup.py egg_info失败,错误代码为1

如果我在没有指定python版本的情况下创建virtualenv就不会发生这种情况......这可能是什么原因造成的?如何使用我选择的python版本创建virtualenv,没有问题?

ps:我使用的是OS X,我使用macports安装了python 2.7.8

编辑: 问题在某种程度上与scrapy依赖的加密lib有关:

running build_ext

building '_Cryptography_cffi_4ed9e37dx4000d087' extension

creating /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography

creating /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat

creating /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings

creating /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__

/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -pipe -Os -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.c -o /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.o

/usr/bin/clang -bundle -undefined dynamic_lookup -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db46 /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.o -lcrypto -lssl -o /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.so

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/setup.py", line 174, in <module>

    "test": PyTest,

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup

    dist.run_commands()

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "<string>", line 15, in replacement_run

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 186, in find_sources

    mm.run()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 246, in run

    self.add_defaults()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 282, in add_defaults

    sdist.add_defaults(self)

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/lib/python2.7/site-packages/setuptools/command/sdist.py", line 167, in add_defaults

    build_py = self.get_finalized_command('build_py')

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command

    cmd_obj.ensure_finalized()

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized

    self.finalize_options()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/lib/python2.7/site-packages/setuptools/command/build_py.py", line 26, in finalize_options

    orig.build_py.finalize_options(self)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_py.py", line 46, in finalize_options

    ('force', 'force'))

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 298, in set_undefined_options

    src_cmd_obj.ensure_finalized()

  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized

    self.finalize_options()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/setup.py", line 88, in finalize_options

    self.distribution.ext_modules = get_ext_modules()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/setup.py", line 68, in get_ext_modules

    OpenSSLBinding().ffi.verifier.get_extension(),

  File "cryptography/hazmat/bindings/openssl/binding.py", line 89, in __init__

    self._ensure_ffi_initialized()

  File "cryptography/hazmat/bindings/openssl/binding.py", line 109, in _ensure_ffi_initialized

    libraries=libraries,

  File "cryptography/hazmat/bindings/utils.py", line 80, in build_ffi

    extra_link_args=extra_link_args,

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cffi-0.8.6-py2.7-macosx-10.8-x86_64.egg/cffi/api.py", line 340, in verify

    lib = self.verifier.load_library()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cffi-0.8.6-py2.7-macosx-10.8-x86_64.egg/cffi/verifier.py", line 75, in load_library

    return self._load_library()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cffi-0.8.6-py2.7-macosx-10.8-x86_64.egg/cffi/verifier.py", line 151, in _load_library

    return self._vengine.load_library()

  File "/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cffi-0.8.6-py2.7-macosx-10.8-x86_64.egg/cffi/vengine_cpy.py", line 149, in load_library

    raise ffiplatform.VerificationError(error)

cffi.ffiplatform.VerificationError: importing '/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.so': dlopen(/Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.so, 2): Symbol not found: _CRYPTO_malloc_debug_init

  Referenced from: /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.so

  Expected in: flat namespace

 in /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_4ed9e37dx4000d087.so

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /Users/davidezanotti/PycharmProjects/scrapy_test/ENV/build/cryptography
Storing debug log for failure in /Users/davidezanotti/.pip/pip.log

似乎我错过了一些开发工具或类似工具...但我不明白为什么我可以成功安装它如果我创建一个环境而没有指定python版本:/

1 个答案:

答案 0 :(得分:2)

virtualenv和python版本的问题有时会链接到库,而python包具有依赖关系。

This post描述了如何解决cryptography依赖问题。