Cannot import name StringIO when importing dateutil

老子叫甜甜 提交于 2019-12-12 04:36:48

问题


I'm having a 'Cannot import name StringIO' error message when importing dateutil which tries to import StringIO but cannot find it. Here is complete trace:

(DEV)arbi@el-oued:~/Work/sentimentpy$ python core/main.py
Traceback (most recent call last):
  File "core/main.py", line 7, in <module>
    from io.reader import *
  File "/home/arbi/Work/sentimentpy/core/io/reader.py", line 4, in <module>
    from dateutil import parser
  File "/home/arbi/DEV/local/lib/python2.7/site-packages/dateutil/parser.py", line 22, in <module>
    from io import StringIO
ImportError: cannot import name StringIO

When I tried to use python3 to launch my program, i had this error:

(DEV)arbi@el-oued:~/Work/sentimentpy$ python3 core/main.py
Traceback (most recent call last):
  File "core/main.py", line 1, in <module>
    from analyzer.length import LengthAnalyzer
  File "/home/arbi/Work/sentimentpy/core/analyzer/length.py", line 4, in <module>
    from numpy
ImportError: No module named numpy

Why I'm having this? i've installed numpy in my virtualenv with: pip install numpy


回答1:


You are masking the built-in io module because you have a package named io in your project:

Traceback (most recent call last):
  File "core/main.py", line 7, in <module>
    from io.reader import *
  File "/home/arbi/Work/sentimentpy/core/io/reader.py", line 4, in <module>

The line from io import StringIO finds /home/arbi/Work/sentimentpy/core/io, not the built-in module.

Rename that package or move it into a new top-level package name that doesn't conflict.

Your second error is unrelated; you simply don't have numpy installed for Python 3.



来源:https://stackoverflow.com/questions/25947227/cannot-import-name-stringio-when-importing-dateutil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!