繁体   English   中英

在OSX上为Anaconda安装QScintilla2:@rpath问题

[英]Installing QScintilla2 for Anaconda on OSX: an @rpath issue

通过大量的汗水和眼泪,我设法编译了QScintilla2( https://www.riverbankcomputing.com/software/qscintilla/download ),以便在Anaconda Python发行版(2.5.0; Python 2.7.11; PyQt4)中使用)在Mac OS X El Capitan上。

编译并安装了Qt4Qt5和Python文件夹中的所有内容而没有错误或警告后,所有内容似乎都已经保存在Anaconda中的正确位置。

但是,当我尝试导入qscintilla2与

import PyQt4.Qsci

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/daniel/anaconda/lib/python2.7/site-packages/PyQt4/Qsci.so, 2): Library not loaded: @rpath/./libQtGui.4.dylib
  Referenced from: /Users/daniel/anaconda/lib/python2.7/site-packages/PyQt4/Qsci.so
  Reason: image not found

因此,该模块似乎无法找到libQtGui.4.dylib

我已经在优秀的博客https://mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html上阅读了@rpath变量,并最终知道了在尝试解决此问题时,必须使用otoolinstall_name_tool

如果我运行otool -L ,将得到以下输出:

Qsci.so:
    libQsci.dylib (compatibility version 0.0.0, current version 0.0.0)
    /Users/daniel/anaconda/lib/libqscintilla2.11.dylib (compatibility version 11.3.0, current version 11.3.0)
    @rpath/./libQtGui.4.dylib (compatibility version 4.8.0, current version 4.8.7)
    @rpath/./libQtCore.4.dylib (compatibility version 4.8.0, current version 4.8.7)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

和otool -l给了我

Qsci.so:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 632
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x000000000009b000
  fileoff 0
 filesize 634880
  maxprot 0x00000007
 initprot 0x00000005
   nsects 7
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000000002450
      size 0x000000000006bcf6
    offset 9296
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x000000000006e146
      size 0x0000000000001956
    offset 450886
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x000000000006fa9c
      size 0x00000000000032ac
    offset 457372
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __TEXT
      addr 0x0000000000072d50
      size 0x0000000000008e47
    offset 470352
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x000000000007bb97
      size 0x0000000000000f62
    offset 506775
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x000000000007cafc
      size 0x00000000000014b4
    offset 510716
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x000000000007dfb0
      size 0x000000000001d048
    offset 516016
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 632
  segname __DATA
   vmaddr 0x000000000009b000
   vmsize 0x0000000000027000
  fileoff 634880
 filesize 159744
  maxprot 0x00000007
 initprot 0x00000003
   nsects 7
    flags 0x0
Section
  sectname __dyld
   segname __DATA
      addr 0x000000000009b000
      size 0x0000000000000010
    offset 634880
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __got
   segname __DATA
      addr 0x000000000009b010
      size 0x0000000000000030
    offset 634896
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 1081 (index into indirect symbol table)
 reserved2 0
Section
  sectname __la_symbol_ptr
   segname __DATA
      addr 0x000000000009b040
      size 0x00000000000021c8
    offset 634944
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000007
 reserved1 1087 (index into indirect symbol table)
 reserved2 0
Section
  sectname __const
   segname __DATA
      addr 0x000000000009d210
      size 0x00000000000050f8
    offset 643600
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __data
   segname __DATA
      addr 0x00000000000a2310
      size 0x000000000001f091
    offset 664336
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __bss
   segname __DATA
      addr 0x00000000000c13b0
      size 0x0000000000000430
    offset 0
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Section
  sectname __common
   segname __DATA
      addr 0x00000000000c17e0
      size 0x0000000000000030
    offset 0
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x00000000000c2000
   vmsize 0x0000000000063000
  fileoff 794624
 filesize 402904
  maxprot 0x00000007
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 40
         name libQsci.dylib (offset 24)
   time stamp 1 Thu Jan  1 01:00:01 1970
      current version 0.0.0
compatibility version 0.0.0
Load command 4
     cmd LC_SYMTAB
 cmdsize 24
  symoff 863408
   nsyms 5494
  stroff 964424
 strsize 233104
Load command 5
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 2227
     iextdefsym 2227
     nextdefsym 2034
      iundefsym 4261
      nundefsym 1233
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 955752
  nindirectsyms 2168
      extreloff 951312
        nextrel 555
      locreloff 794624
        nlocrel 7955
Load command 6
     cmd LC_UUID
 cmdsize 24
    uuid 888BE029-40E0-3D69-83D4-B236B57ADFD4
Load command 7
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.5
      sdk 10.11
Load command 8
          cmd LC_LOAD_DYLIB
      cmdsize 80
         name /Users/daniel/anaconda/lib/libqscintilla2.11.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 11.3.0
compatibility version 11.3.0
Load command 9
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name @rpath/./libQtGui.4.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 4.8.7
compatibility version 4.8.0
Load command 10
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name @rpath/./libQtCore.4.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 4.8.7
compatibility version 4.8.0
Load command 11
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libstdc++.6.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 104.1.0
compatibility version 7.0.0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1226.10.1
compatibility version 1.0.0
Load command 13
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 858264
 datasize 5144
Load command 14
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 863408
 datasize 0

据我所知,此模块中没有@rpath条目(或者至少我应该找到LC_RPATH命令?)。 我当然可以在以后使用install_name_tool进行设置,但这就是我遇到的问题。

我不明白在这种情况下Qsci.so模块将其视为@loader_path和@executable_path的原因。 它位于

/Users/daniel/anaconda/lib/python2.7/site-packages/PyQt4/Qsci.so

但这似乎是直接引用

/Users/daniel/anaconda/lib/libqscintilla2.11.dylib

因此,在这种情况下,/ Users / daniel / anaconda / lib / python2.7 / site-packages / PyQt4 /或/ Users / daniel / anaconda / lib /是@loader_path吗? 我假设@executable_path只是指向/ Users / daniel / anaconda / bin中的Python解释器的路径,但是如果我错了,请更正我。

libQtGui.4.dylib和libQtCore.4.dylib都位于

/Users/daniel/anaconda/lib/

我试图手动添加我认为正确的@rpaths

install_name_tool -add_rpath @loader_path/../../ Qsci.so
install_name_tool -add_rpath @loader_path/../lib Qsci.so

第一个条目假设Qsci.so的包含文件夹为@loader_path,第二个条目为libqscintilla2.11.dylib,但无济于事。

如果我将绝对路径添加到@rpath

install_name_tool -add_rpath /Users/daniel/anaconda/lib Qsci.so

它确实解决了问题,所以我确实知道这是一个rpath问题。 不过,我确实需要相对位置,因为一旦我准备好了,我打算打包该应用程序。

感谢您提供的任何帮助,我很抱歉本帖子的发布时间超出了预期!

通过检查其他PyQt4模块,我发现我必须添加一个rpath条目,其install_name_tool指向Qsci.so中的@loader_path /../../../。 在下面,您将找到一个bash脚本,该脚本贯穿Mac上用于Anaconda的QScintilla2的整个安装过程。

#!/bin/bash
# Run this file from within the root of the QScintilla source folder

# Go to Qscintilla source dir
cd Qt4Qt5
# Build the makefile with qmake, specify llvm as the compiler
# The normal g++ compiler causes an __Unwind_Resume error at linking phase
~/anaconda/bin/qmake qscintilla.pro -spec macx-llvm
# Build Qscintilla
make
# and install it
make install

# Go to python folder
cd ../Python

# Configure compilation of Python Qsci module
~/anaconda/bin/python configure.py -q ~/anaconda/bin/qmake --sip ~/anaconda/bin/sip -n ~/anaconda/include -o ~/anaconda/lib
# make it
make
# Add the correct @rpath entry to Qsci.so so it can find the other required Qt modules
install_name_tool -add_rpath @loader_path/../../../ Qsci.so
# Install QSci.so to the site-packages/PyQt4 folder
make install

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM