Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

python - Cannot import name StringIO when importing dateutil

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...