将virtualenv与Anaconda一起使用需要LD_LIBRARY_PATH更改,但会破坏Emacs

时间:2014-01-09 19:57:28

标签: python emacs virtualenv anaconda

我遇到的问题类似于this postthis post中描述的问题,但我认为这个问题有所不同(或至少没有得到相关文章的任何答案或评论的回答) 。我还发现this Google groups reply声明不要将LD_LIBRARY_PATH与Anaconda一起使用,但觉得它不正确。

  1. 我将virtualenv和virtualenvwrapper设置为explained here

  2. 我将Anaconda安装到/ home / usrname / anaconda

  3. 我试图像这样为Anaconda创建一个virtualenv:

    mkvirtualenv anaconda -p /home/usrname/anaconda/bin/python

  4. 但收到以下错误,表明整个发现 - 系统 - 蟒蛇 - 而不是下载 - 2.7.5-python Acaconda问题:

    espears@espears-w:~/anaconda/bin$ mkvirtualenv anaconda -p /home/espears/anaconda/bin/python
    Running virtualenv with interpreter /home/espears/anaconda/bin/python
    New python executable in anaconda/bin/python
    Installing setuptools, pip...
      Complete output from command /home/espears/anacon.../anaconda/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip:
      Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/__init__.py", line 3, in <module>
      File "/home/espears/anaconda/lib/python2.7/optparse.py", line 77, in <module>
        import textwrap
      File "/home/espears/anaconda/lib/python2.7/textwrap.py", line 10, in <module>
        import string, re
      File "/home/espears/anaconda/lib/python2.7/string.py", line 83, in <module>
        import re as _re
      File "/home/espears/anaconda/bin/anaconda/lib/python2.7/re.py", line 105, in <module>
        import sre_compile
      File "/home/espears/anaconda/bin/anaconda/lib/python2.7/sre_compile.py", line 14, in <module>
        import sre_parse
      File "/home/espears/anaconda/bin/anaconda/lib/python2.7/sre_parse.py", line 17, in <module>
        from sre_constants import *
      File "/home/espears/anaconda/bin/anaconda/lib/python2.7/sre_constants.py", line 18, in <module>
        from _sre import MAXREPEAT
    ImportError: cannot import name MAXREPEAT
    ----------------------------------------
    ...Installing setuptools, pip...done.
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2334, in <module>
        main()
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 820, in main
        symlink=options.symlink)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 988, in create_environment
        install_wheel(to_install, py_executable, search_dirs)
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 956, in install_wheel
        'PIP_NO_INDEX': '1'
      File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 898, in call_subprocess
        % (cmd_desc, proc.returncode))
    OSError: Command /home/espears/anacon.../anaconda/bin/python -c "import sys, pip; pip...ll\"] + sys.argv[1:])" setuptools pip failed with error code 1
    

    我将/home/espears/anaconda/lib/导出到LD_LIBRARY_PATH,然后virtualenv命令完全没有问题。然后我可以做workon anaconda并正确找到了anaconda 2.7.5版本的Python,一切都很棒。

    但后来我尝试启动Emacs,它出现(如在顶部的链接帖子中)Anaconda在LD_LIBRARY_PATH中的位置为Emacs造成了问题:

    espears@espears-w:~$ emacs
    Gtk-Message: Failed to load module "canberra-gtk-module"
    emacs: symbol lookup error: /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0: undefined symbol: cairo_ft_font_options_substitute
    

    所以问题是:出了什么问题?如果我取消设置LD_LIBRARY_PATH的内容,那么anaconda virtualenv只使用系统默认的Python。但如果我单独离开LD_LIBRARY_PATH,我就无法启动Emacs。

    将Anaconda所需的内容导出到ldd (which emacs)后,以下是LD_LIBRARY_PATH的输出:

    espears@espears-w:~$ export LD_LIBRARY_PATH='/home/espears/anaconda/lib/':$LD_LIBRARY_PATH
    espears@espears-w:~$ ldd $(which emacs)
        linux-vdso.so.1 =>  (0x00007fff0a7fe000)
        libtiff.so.4 => /usr/lib/x86_64-linux-gnu/libtiff.so.4 (0x00007f504f455000)
        libjpeg.so.8 => /home/espears/anaconda/lib/libjpeg.so.8 (0x00007f504f21e000)
        libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f504eff5000)
        libm.so.6 => /home/espears/anaconda/lib/libm.so.6 (0x00000032b9600000)
        libgif.so.4 => /usr/lib/x86_64-linux-gnu/libgif.so.4 (0x00007f504edec000)
        libXpm.so.4 => /usr/lib/x86_64-linux-gnu/libXpm.so.4 (0x00007f504ebda000)
        libgtk-3.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f504e552000)
        libgdk-3.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007f504e2d4000)
        libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f504df84000)
        libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f504dd64000)
        libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f504db1b000)
        libcairo.so.2 => /home/espears/anaconda/lib/libcairo.so.2 (0x00007f504d841000)
        libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f504d5f2000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f504d2fd000)
        libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f504d0f4000)
        libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f504ceda000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f504cba5000)
        libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f504c99a000)
        libXft.so.2 => /usr/lib/x86_64-linux-gnu/libXft.so.2 (0x00007f504c785000)
        libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007f504c498000)
        librsvg-2.so.2 => /usr/lib/x86_64-linux-gnu/librsvg-2.so.2 (0x00007f504c262000)
        libMagickWand.so.4 => /usr/lib/libMagickWand.so.4 (0x00007f504bf4d000)
        libMagickCore.so.4 => /usr/lib/libMagickCore.so.4 (0x00007f504baca000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f504b8c1000)
        libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f504b67d000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f504b460000)
        libxml2.so.2 => /home/espears/anaconda/lib/libxml2.so.2 (0x00007f504b114000)
        libgpm.so.2 => /usr/lib/x86_64-linux-gnu/libgpm.so.2 (0x00007f504af0e000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f504ace7000)
        libgconf-2.so.4 => /usr/lib/x86_64-linux-gnu/libgconf-2.so.4 (0x00007f504aab8000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f504a899000)
        libfreetype.so.6 => /home/espears/anaconda/lib/libfreetype.so.6 (0x00007f504a612000)
        libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f504a3db000)
        libotf.so.0 => /usr/lib/libotf.so.0 (0x00007f504a1c6000)
        libm17n-flt.so.0 => /usr/lib/libm17n-flt.so.0 (0x00007f5049fbb000)
        libm17n-core.so.0 => /usr/lib/libm17n-core.so.0 (0x00007f5049d8d000)
        libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007f5049ad1000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5049711000)
        libz.so.1 => /home/espears/anaconda/lib/libz.so.1 (0x00007f50494fb000)
        libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f50492f7000)
        libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f50490ea000)
        libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f5048eda000)
        libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f5048cd4000)
        libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f5048ab2000)
        libcairo-gobject.so.2 => /usr/lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f50488a8000)
        libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f504867e000)
        libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f504846d000)
        libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f5048269000)
        libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f5048061000)
        libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f5047e57000)
        libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f5047c53000)
        libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f5047a50000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f5047833000)
        libpixman-1.so.0 => /home/espears/anaconda/lib/libpixman-1.so.0 (0x00007f50475b4000)
        libpng15.so.15 => /home/espears/anaconda/lib/libpng15.so.15 (0x00007f504737d000)
        libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f5047174000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f5046f37000)
        libuuid.so.1 => /home/espears/anaconda/lib/libuuid.so.1 (0x00007f5046d33000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f5046b14000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5046910000)
        libcroco-0.6.so.3 => /usr/lib/x86_64-linux-gnu/libcroco-0.6.so.3 (0x00007f50466d6000)
        libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f50464c7000)
        liblcms.so.1 => /usr/lib/x86_64-linux-gnu/liblcms.so.1 (0x00007f5046290000)
        liblqr-1.so.0 => /usr/lib/liblqr-1.so.0 (0x00007f504607c000)
        libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f5045e6b000)
        libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f5045c61000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f504f6ce000)
        libdbus-glib-1.so.2 => /usr/lib/x86_64-linux-gnu/libdbus-glib-1.so.2 (0x00007f5045a3a000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f5045810000)
        libthai.so.0 => /usr/lib/x86_64-linux-gnu/libthai.so.0 (0x00007f5045606000)
        libtasn1.so.3 => /usr/lib/x86_64-linux-gnu/libtasn1.so.3 (0x00007f50453f5000)
        libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007f5045177000)
        libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f5044f64000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f5044d60000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f5044b5a000)
        libdatrie.so.1 => /usr/lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f5044954000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f504474f000)
    

2 个答案:

答案 0 :(得分:1)

您可以尝试以下任一建议:

  1. 例如,通过定义别名LD_LIBRARY_PATH来启用emacs时取消设置alias emacs='LD_LIBRARY_PATH= emacs'(请注意空白),或者

  2. export LD_PRELOAD = $(ldd $(which emacs)| grep libpangocairo | awk'{print $ 3}')强制使用系统范围的安装libpangocairo库。但这可能打破了anaconda。

答案 1 :(得分:1)

您不想使用LD_LIBRARY_PATH的原因是它更改了动态库加载器搜索路径的顺序。因为Anaconda测试所有库以便它们在所有系统上协同工作,所以它会打包许多比系统版本更旧的库。您拥有的emacs使用的旧系统库会导致崩溃。

现在mkvirtualenv失败的原因是没有正确复制与Anaconda链接的python和其他库,并且动态库中的链接指针被破坏。

首选解决方案是使用conda工具创建环境。例如:

conda create -p ~/anaconda/envs/test2 anaconda=1.4.0 python=2.7 numpy=1.6

请参阅http://docs.continuum.io/conda/examples/create.html