使用pycocotools时出现"undefined symbol: _Py_ZeroStruct"

来源:互联网 发布:折800淘宝 编辑:程序博客网 时间:2024/06/06 13:20

问题描述:

运行

from pycocotools.coco import COCO

报错:

ImportError: /home/elijha/PycharmProjects/LinkinNet/cocoapi-master/PythonAPI/pycocotools/_mask.so: undefined symbol: _Py_ZeroStruct

出错原因

stackoverflow的回答:

This error message is typical when there’s a version mismatch in Python modules. It could something like cython_bbox.so was compiled and linked against Python 2.7 and CNTK was compiled against Python 3.5. It’s hard to say exactly what the reason is but you can try to do make inside a python environment that matches your CNTK version and see if that works.

检查后发现,我把Cython安装在了python2.7的环境内,而且make也是在此环境下进行的。而import的环境是python3.5,因此出错。

解决方法

  1. 在python2.7下卸载Cython。(这一步其实可以不做,但是因为我从来不用这个环境,就也卸载了。)
  2. 进入python3.5,执行pip install Cython
  3. 重进进入pycocotools文件夹,执行make。(即用python3重新运行pycocotools下的setup.py进行安装。)
  4. 重新运行from pycocotools.coco import COCO,正确。
阅读全文
1 0
原创粉丝点击