问题
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