导入运行 yum 所需的 Python 模块之一时出现问题

导入运行 yum 所需的 Python 模块之一时出现问题

我正确安装了 VTK 5.1 的 Python 绑定。在Python中,import vtk可以工作,但import itk还没有工作。所以我想安装 ITK 4.2 的 Python 绑定。

./configure我需要安装 SWIG 2.0.7,从SWIG 源目录中出现的错误消息中,我知道我需要安装pcre.所以我选择了pcre的8.31版本。以下是该过程的摘要:

(VTK + Python) ---> 这有效。

(ITK + Python) ---> 需要 SWIG ---> 需要 PCRE

现在 pcre 已安装,我的问题是 yum 已停止工作:

[root@wok build]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   libvtkIOPythonD.so.5.10: cannot open shared object file: No such file or directory

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7 (r27:82500, Sep 16 2010, 18:02:00) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

我想知道是否应该将变量添加到 PATH 中。

也许这与我使用 SWIG 时遇到的问题有关:它以用户身份工作,但不能以 root 身份工作。

wok ~ $ swig -swiglib
/usr/local/share/swig/2.0.7

[root@wok home]# swig -swiglib
swig: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

我必须在 root 用户的 .bashrc 中添加一行,以使 swig 能够与用户和 root 一起使用:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/

Python 路径中可能存在某些内容。

在 Python 中,我注意到我可以import vtk作为用户,但不能作为 root。

wok ~ $ python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
>>> 

但:

[root@wok ~]# python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/user/wok/home/Softwares/VTK_5.1/build/Wrapping/Python/vtk/__init__.py", line 41, in <module>
    from vtkCommonPython import *
ImportError: libvtkCommonPythonD.so.5.10: cannot open shared object file: No such file or directory

PCRE 在我看来安装正确:

[root@wok build]# pcretest -C
PCRE version 8.31 2012-07-06
Compiled with
  8-bit support only
  No UTF-8 support
  No Unicode properties support
  No just-in-time compiler support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

[root@wok build]# locate libpcre
/lib64/libpcre.so.0
/lib64/libpcre.so.0.0.1
/usr/lib64/libpcrecpp.so.0
/usr/lib64/libpcrecpp.so.0.0.0
/usr/lib64/libpcreposix.so.0
/usr/lib64/libpcreposix.so.0.0.0

答案1

该问题与 PYTHONPATH 有关。可以通过从.bashrc我有的四行中删除一行来解决从教程复制的:

export PYTHONPATH=$PYTHONPATH:~/Softwares/VTK_5.1/build/Wrapping/Python/vtk/

我保留了以下三行:

export PYTHONPATH=$PYTHONPATH:~/Softwares/VTK_5.1/build/Wrapping/Python/
export PYTHONPATH=$PYTHONPATH:~/Softwares/VTK_5.1/build/bin/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/Softwares/VTK_5.1/build/bin/

现在,我可以import vtk作为用户,并且仍然yum以 root 身份使用。我不能import vtk作为 root,但我从来不想这样做。

为了解决这个问题,我首先删除了该.bashrc文件并发现它已修复yum。然后我继续将上面的行添加到 中以PYTHONPATH访问import vtk.最后,我注意到ipython什么时候有用,什么时候import vtk有用,而且是相反的。

相关内容