【问题标题】:Mutalyzer py.test fails with python-magic errorMutalyzer py.test 因 python-magic 错误而失败
【发布时间】:2016-01-11 12:39:29
【问题描述】:

我正在尝试按照these 说明使用Anaconda Python 2.7Centos 6.7 上安装mutalyzer 2.0.14

我的安装很顺利,但是当我尝试运行 py.test 套件时出现一系列失败。

我怀疑操作系统的libmagic 和python2.7 包python-magic 之间存在版本冲突。

如果有人能解释这里发生了什么或者更好地建议解决这个问题,我会非常感兴趣。

我的 libmagic 安装:

$ rpm -qa | grep 'file-'
file-libs-5.04-21.el6.x86_64
file-5.04-21.el6.x86_64
file-devel-5.04-21.el6.x86_64

对应的Python包:

$ source activate  py27
discarding /opt/anaconda2/bin from PATH
prepending /opt/anaconda2/envs/py27/bin to PATH
(py27) $ pip list | grep magic 
Magic-file-extensions (0.2, /home/chris.guest/temp/mutalyzer/src/magic-file-extensions)
python-magic (0.4.10)

py.test 是这样开始的:

# py.test
======================================================= test session starts =======================================================
platform linux2 -- Python 2.7.11, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /home/chris.guest/temp/mutalyzer, inifile: 
collected 610 items / 3 errors 

tests/test_backtranslator.py ......
tests/test_base.py .
tests/test_crossmap.py .......................
tests/test_grammar.py ........................................................................................
tests/test_mapping.py ..............................
tests/test_migrations.py .
tests/test_mutator.py ................................................................................................................................................................
tests/test_ncbi.py ............................................................................................................
tests/test_parsers_genbank.py ..........

并以很多错误结束。由于undefined symbol: magic_list,许多测试失败:

_________________________________________ ERROR at setup of test_batch_unicode[sqlite://] _________________________________________

    @pytest.fixture
    def website():
>       return create_app().test_client()

tests/test_website.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
mutalyzer/website/__init__.py:35: in create_app
    from mutalyzer.website.views import website
mutalyzer/website/views.py:26: in <module>
    from mutalyzer import (announce, backtranslator, File, Retriever, Scheduler,
mutalyzer/File.py:23: in <module>
    import magic           # open(), MAGIC_MIME, MAGIC_NONE
src/magic-file-extensions/magic.py:94: in <module>
    _list = _libraries['magic'].magic_list
/opt/anaconda2/envs/py27/lib/python2.7/ctypes/__init__.py:378: in __getattr__
    func = self.__getitem__(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <CDLL 'libmagic.so.1', handle 160cc50 at 7f23b97340d0>, name_or_ordinal = 'magic_list'

    def __getitem__(self, name_or_ordinal):
>       func = self._FuncPtr((name_or_ordinal, self))
E       AttributeError: /usr/lib64/libmagic.so.1: undefined symbol: magic_list

/opt/anaconda2/envs/py27/lib/python2.7/ctypes/__init__.py:383: AttributeError
______________________________________ ERROR at setup of test_batch_unicode_email[sqlite://] ______________________________________

    @pytest.fixture
    def website():
>       return create_app().test_client()

tests/test_website.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
mutalyzer/website/__init__.py:35: in create_app
    from mutalyzer.website.views import website
mutalyzer/website/views.py:26: in <module>
    from mutalyzer import (announce, backtranslator, File, Retriever, Scheduler,
mutalyzer/File.py:23: in <module>
    import magic           # open(), MAGIC_MIME, MAGIC_NONE
src/magic-file-extensions/magic.py:94: in <module>
    _list = _libraries['magic'].magic_list
/opt/anaconda2/envs/py27/lib/python2.7/ctypes/__init__.py:378: in __getattr__
    func = self.__getitem__(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <CDLL 'libmagic.so.1', handle 160cc50 at 7f23b984ef50>, name_or_ordinal = 'magic_list'

    def __getitem__(self, name_or_ordinal):
>       func = self._FuncPtr((name_or_ordinal, self))
E       AttributeError: /usr/lib64/libmagic.so.1: undefined symbol: magic_list

/opt/anaconda2/envs/py27/lib/python2.7/ctypes/__init__.py:383: AttributeError
============================================== 548 passed, 65 error in 41.42 seconds ==============================================
(py27)[root@localhost mutalyzer]# 

【问题讨论】:

    标签: python anaconda centos6


    【解决方案1】:

    我们之前有一份报告称,一位用户试图在 CentOS 6 上安装 Mutalyzer,但他们也遇到了 libmagic 的问题。除了他们切换到 CentOS 7 之外,我认为这没有得到解决。

    不幸的是,我们的资源非常有限,而 Debian 是我们自己使用的唯一操作系统,这是我们可以实际支持的全部。当然,我们很乐意接受补丁或文档更新 :)

    感谢您使用 Mutalyzer!

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post。 - From Review
    • 抱歉,我试图将此作为评论留下,但由于它需要一定的声誉而被拒绝。另外,由于我是所引用软件(Mutalyzer)的主要维护者,因此这是您将获得的有关如何运行 Mutalyzer 的最权威答案:升级到 CentOS 7 或在 Debian 上运行。我相信这为问题提供了 a 解决方案,这正是@ChrisGuest 所要求的。如果问题是关于如何在 CentOS 6 上使用 python-magic 的问题更笼统,我同意我对此没有答案。
    • @MartijnVermaat 感谢您对此的回复。我会暂时保留这个问题,看看是否有其他人对此有回应。如果一切都失败了,我可能会委托一个 Centos7 机器。
    • @ChrisGuest 我可以补充一点,我们还有一个Ansible playbook 可以在生产环境中自动部署 Mutalyzer。不过,这与 Debian 8 的耦合更紧密(但附带了一个 Vagrant 用于快速测试的配方)。当然,请随时与我们联系(请参阅 Mutalyzer 网站上的联系链接)。
    • @ChrisGuest 谢谢,我按照您上面的建议在 CentOS 6 上安装了 Mutalyzer(希望没有测试)。 (无法评论您的回答)。
    【解决方案2】:

    Centos 6.7 打包的magiclib 版本缺少magic_list 函数。

    我能够将这个补丁添加到src/magic-file-extensions/magic.py,以便 py.test 可以正常运行。

    $ diff -u src/magic-file-extensions/magic.old.py src/magic-file-extensions/magic.py
    --- src/magic-file-extensions/magic.old.py  2015-12-31 14:04:50.769635453 +1100
    +++ src/magic-file-extensions/magic.py  2016-01-11 15:17:49.987270845 +1100
    @@ -91,9 +91,13 @@
     _check.restype = c_int
     _check.argtypes = [magic_t, c_char_p]
    
    -_list = _libraries['magic'].magic_list
    -_list.restype = c_int
    -_list.argtypes = [magic_t, c_char_p]
    +try:
    +    _list = _libraries['magic'].magic_list
    +    _list.restype = c_int
    +    _list.argtypes = [magic_t, c_char_p]
    +except AttributeError, e:
    +    _list = None
    +    
    
     _errno = _libraries['magic'].magic_errno
     _errno.restype = c_int
    

    虽然使用此补丁处理直接的AttributeError,但如果调用src/magic-file-extensions/magic.py 中的Magic.list 方法,它仍然会失败。这不是一个直接的问题,因为它似乎没有在 mutalyzer 代码库中被调用。

    【讨论】:

    • @MartijnVermaat 如果您认为有帮助,请随时将此补丁添加到mutalyzer 代码库。
    猜你喜欢
    • 2018-09-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多