欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-05-26 23:40:52
...

问题描述:

运行

from pycocotools.coco import COCO

报错:

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

出错原因

*的回答

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,正确。