ImportError: cannot import name BytesIO on eclipse
ImportError: cannot import name BytesIO on eclipse
我收到以下错误,只是无法弄清楚为什么无法导入 gensim。我尝试通过创建虚拟环境再次重新导入 gensim,但效果不佳。
我是新手python,请大方
Traceback (most recent call last):
File "C:\Users\Tejasvi\workspace\major project\Tag Recommendation\test.py", line 6, in <module>
import gensim
File "C:\Python27\lib\site-packages\gensim\__init__.py", line 6, in <module>
from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization
File "C:\Python27\lib\site-packages\gensim\models\__init__.py", line 18, in <module>
from . import wrappers
File "C:\Python27\lib\site-packages\gensim\models\wrappers\__init__.py", line 5, in <module>
from .ldamallet import LdaMallet
File "C:\Python27\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 40, in <module>
from smart_open import smart_open
File "C:\Python27\lib\site-packages\smart_open\__init__.py", line 1, in <module>
from .smart_open_lib import *
File "C:\Python27\lib\site-packages\smart_open\smart_open_lib.py", line 34, in <module>
from boto.compat import BytesIO, urlsplit, six
ImportError: cannot import name BytesIO
这是我的代码:
import string
import re
import gensim
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
stop_words.update(['.', ',', '"', "'", '?', '!', ':', ';', '(', ')', '[', ']',
'{', '}', 'lt', 'gt','xA', '/', 'lt'])
outFile = open('C:/Users/Tejasvi/Desktop/major/preprocessed/c#.txt', 'w')
with open('C:/Users/Tejasvi/Desktop/major/3/c#.txt') as f:
for line in f:
new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', line)
new_string = ' '.join([w for w in new_str.split() if len(w)>2])
for c in string.punctuation:
new_string=new_string.replace(c,"")
for w in new_string.split():
if w.lower() not in stop_words:
outFile.write(w)
outFile.write(" ")
outFile.close()
from gensim import corpora
with open ('C:/Users/Tejasvi/Desktop/major/preprocessed/c#.txt', 'r') as f:
for line in f:
dictionary = corpora.Dictionary(line.strip().split())
这里是 pip freeze 的输出
-curses==2.2
alabaster==0.7.6
alembic==0.7.6
astroid==1.3.6
astropy==1.0.3
Babel==1.3
backports.datetime-timestamp==1.0.2.dev0
backports.functools-lru-cache==1.0.2.dev0
backports.method-request==1.0.1.dev0
backports.shutil-get-terminal-size==1.0.0
backports.ssl-match-hostname==3.4.0.2
Beaker==1.7.0
BeautifulSoup==3.2.1
beautifulsoup4==4.3.2
blinker==1.4.dev0
blosc==1.2.7
bloscpack==0.7.2
boto==2.24.0
Bottleneck==1.0.0
bz2file==0.98
CacheControl==0.11.5
cchardet==0.3.5
cdecimal==2.3
certifi==2015.4.28
cffi==1.1.2
chardet==2.3.0
colorama==0.3.3
configobj==5.0.6+xy.1
configparser==3.5.0b2
cov-core==1.15.0
coverage==3.7.1
cryptography==1.0.dev1
cssselect==0.9.1
cx-Freeze==4.3.4
cyordereddict==0.2.3.dev7
datrie==0.7.1.dev37
decorator==3.4.0
distlib==0.2.0
docutils==0.12
ecdsa==0.13.1.dev0
ed25519ll==0.6
enum34==1.0.4
faulthandler==2.4
formlayout==1.0.15
funcsigs==0.4
futures==3.0.3
gensim==0.12.4
gevent==1.0.2
gevent-websocket==0.9.5
GraphLab-Create==0.9.1
greenlet==0.4.7
grin==1.2.1+xy1
guidata==1.6.1
guiqwt==2.3.2
h5py==2.5.0
html5lib==0.99999
httpretty==0.8.10
idna==2.1.dev1
ipaddress==1.0.7
ipdb==0.8.1
ipdbplugin==1.4.2
ipython==2.4.1
jaraco.apt==1.0
jaraco.classes==1.2
jaraco.collections==1.1
jaraco.context==1.3
jaraco.functools==1.3
jaraco.structures==1.0
jaraco.text==1.4
jaraco.ui==1.3.1
jaraco.windows==3.4
jedi==0.9.0
Jinja2==2.7.3
keyring==5.3
lda==1.0.3
libnacl==1.4.3
librato-metrics==0.4.9
linecache2==1.0.0
lockfile==0.10.2.post7
logilab-common==0.63.2
lxml==3.4.4
mahotas==1.3.0
Mako==1.0.1
MarkupSafe==0.23
matplotlib==1.4.3
mixpanel-py==3.1.1
mock==1.0.1
modernize==0.4
more-itertools==2.3.dev0
ndg-httpsclient==0.4.0
netifaces==0.10.4
nltk==3.1
nose==1.3.7
nose-cov==1.6
nose-fixes==1.3
numexpr==2.4.3
numpy==1.10.4
numpydoc==0.6.dev0
oauthlib==0.7.3.dev0
objgraph==2.0.1.dev0
packaging==15.2
pandas==0.16.2
paramiko==1.15.2
pathlib==1.0.1
patsy==0.3.0
pbr==1.8.1
pep8==1.6.2
Pillow==2.8.2
ply==3.6
prettytable==0.7.2
psutil==1.1.3
psycopg2==2.6.1
py==1.4.30
py2exe==0.6.9
pyasn1==0.1.8
pyasn1-modules==0.0.6
PyAudio==0.2.8
pycparser==2.14
pycrypto==2.6.1
pyemf==2.0.0
pyflakes==0.9.2
Pygments==2.0.2
PyICU==1.9.2+xy.1
PyJWT==1.3.1.dev2
pylint==1.4.3
pyMinuit==1.2.1
PyOpenGL==3.1.0
PyOpenGL-accelerate==3.1.0
pyOpenSSL==0.15.1
pyparsing==2.0.3
PyQt4==4.11.3
pyreadline==2.0.6+xy.1
PyStemmer==1.3.0
python-dateutil==2.4.2
pytz==2015.4
pywin==0.3.1
pywin32==219
PyYAML==3.11
pyzmq==14.7.0
reportlab==3.2.0
requests==2.8.1
requests-oauthlib==0.5.0
rope==0.10.2
sampy==1.2.1
scandir==1.1.1.dev7
scikit-learn==0.17
scipy==0.15.1
scp==0.10.2
singledispatch==3.4.0.3
six==1.9.0
smart-open==1.3.2
snowballstemmer==1.2.1.dev1
Sphinx==1.3.2
sphinx-rtd-theme==0.1.8
sphinxcontrib-plantuml==0.6
spyder==2.3.5.2
SQLAlchemy==1.0.6
statsmodels==0.6.1
stop-words==2015.2.23.1
tables==3.2.0
Tempita==0.5.2
textmining==1.0
tornado==3.2.1
traceback2==1.4.0
ujson==1.33
unittest2==1.0.1
urllib3==1.10.4
veusz==1.23.1
virtualenv==13.0.3
virtualenvwrapper-win==1.2.1
ViTables==2.2a1
wheel==0.24.0
Whoosh==2.7.0
wincertstore==0.2
wsaccel==0.6.2
wxPython==2.8.12.1
wxPython-common==2.8.12.1
yappi==0.94
yg.lockfile==2.0
zc.lockfile==1.1.0
我还检查了我是否有自己的 io.py 版本,但它不存在。
我在使用此版本的 boto 时遇到了类似的错误消息:
>>> import boto
>>> boto.__version__
'2.20.1'
解决问题后(删除隐藏新版本的旧版本)我设法加载了 gensim:
>>> import boto
>>> boto.__version__
'2.39.0'
>>> import gensim
>>>
我建议您尝试将 boto 更新到更新的版本。
pip install boto --upgrade
我收到以下错误,只是无法弄清楚为什么无法导入 gensim。我尝试通过创建虚拟环境再次重新导入 gensim,但效果不佳。 我是新手python,请大方
Traceback (most recent call last):
File "C:\Users\Tejasvi\workspace\major project\Tag Recommendation\test.py", line 6, in <module>
import gensim
File "C:\Python27\lib\site-packages\gensim\__init__.py", line 6, in <module>
from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization
File "C:\Python27\lib\site-packages\gensim\models\__init__.py", line 18, in <module>
from . import wrappers
File "C:\Python27\lib\site-packages\gensim\models\wrappers\__init__.py", line 5, in <module>
from .ldamallet import LdaMallet
File "C:\Python27\lib\site-packages\gensim\models\wrappers\ldamallet.py", line 40, in <module>
from smart_open import smart_open
File "C:\Python27\lib\site-packages\smart_open\__init__.py", line 1, in <module>
from .smart_open_lib import *
File "C:\Python27\lib\site-packages\smart_open\smart_open_lib.py", line 34, in <module>
from boto.compat import BytesIO, urlsplit, six
ImportError: cannot import name BytesIO
这是我的代码:
import string
import re
import gensim
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
stop_words.update(['.', ',', '"', "'", '?', '!', ':', ';', '(', ')', '[', ']',
'{', '}', 'lt', 'gt','xA', '/', 'lt'])
outFile = open('C:/Users/Tejasvi/Desktop/major/preprocessed/c#.txt', 'w')
with open('C:/Users/Tejasvi/Desktop/major/3/c#.txt') as f:
for line in f:
new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', line)
new_string = ' '.join([w for w in new_str.split() if len(w)>2])
for c in string.punctuation:
new_string=new_string.replace(c,"")
for w in new_string.split():
if w.lower() not in stop_words:
outFile.write(w)
outFile.write(" ")
outFile.close()
from gensim import corpora
with open ('C:/Users/Tejasvi/Desktop/major/preprocessed/c#.txt', 'r') as f:
for line in f:
dictionary = corpora.Dictionary(line.strip().split())
这里是 pip freeze 的输出
-curses==2.2
alabaster==0.7.6
alembic==0.7.6
astroid==1.3.6
astropy==1.0.3
Babel==1.3
backports.datetime-timestamp==1.0.2.dev0
backports.functools-lru-cache==1.0.2.dev0
backports.method-request==1.0.1.dev0
backports.shutil-get-terminal-size==1.0.0
backports.ssl-match-hostname==3.4.0.2
Beaker==1.7.0
BeautifulSoup==3.2.1
beautifulsoup4==4.3.2
blinker==1.4.dev0
blosc==1.2.7
bloscpack==0.7.2
boto==2.24.0
Bottleneck==1.0.0
bz2file==0.98
CacheControl==0.11.5
cchardet==0.3.5
cdecimal==2.3
certifi==2015.4.28
cffi==1.1.2
chardet==2.3.0
colorama==0.3.3
configobj==5.0.6+xy.1
configparser==3.5.0b2
cov-core==1.15.0
coverage==3.7.1
cryptography==1.0.dev1
cssselect==0.9.1
cx-Freeze==4.3.4
cyordereddict==0.2.3.dev7
datrie==0.7.1.dev37
decorator==3.4.0
distlib==0.2.0
docutils==0.12
ecdsa==0.13.1.dev0
ed25519ll==0.6
enum34==1.0.4
faulthandler==2.4
formlayout==1.0.15
funcsigs==0.4
futures==3.0.3
gensim==0.12.4
gevent==1.0.2
gevent-websocket==0.9.5
GraphLab-Create==0.9.1
greenlet==0.4.7
grin==1.2.1+xy1
guidata==1.6.1
guiqwt==2.3.2
h5py==2.5.0
html5lib==0.99999
httpretty==0.8.10
idna==2.1.dev1
ipaddress==1.0.7
ipdb==0.8.1
ipdbplugin==1.4.2
ipython==2.4.1
jaraco.apt==1.0
jaraco.classes==1.2
jaraco.collections==1.1
jaraco.context==1.3
jaraco.functools==1.3
jaraco.structures==1.0
jaraco.text==1.4
jaraco.ui==1.3.1
jaraco.windows==3.4
jedi==0.9.0
Jinja2==2.7.3
keyring==5.3
lda==1.0.3
libnacl==1.4.3
librato-metrics==0.4.9
linecache2==1.0.0
lockfile==0.10.2.post7
logilab-common==0.63.2
lxml==3.4.4
mahotas==1.3.0
Mako==1.0.1
MarkupSafe==0.23
matplotlib==1.4.3
mixpanel-py==3.1.1
mock==1.0.1
modernize==0.4
more-itertools==2.3.dev0
ndg-httpsclient==0.4.0
netifaces==0.10.4
nltk==3.1
nose==1.3.7
nose-cov==1.6
nose-fixes==1.3
numexpr==2.4.3
numpy==1.10.4
numpydoc==0.6.dev0
oauthlib==0.7.3.dev0
objgraph==2.0.1.dev0
packaging==15.2
pandas==0.16.2
paramiko==1.15.2
pathlib==1.0.1
patsy==0.3.0
pbr==1.8.1
pep8==1.6.2
Pillow==2.8.2
ply==3.6
prettytable==0.7.2
psutil==1.1.3
psycopg2==2.6.1
py==1.4.30
py2exe==0.6.9
pyasn1==0.1.8
pyasn1-modules==0.0.6
PyAudio==0.2.8
pycparser==2.14
pycrypto==2.6.1
pyemf==2.0.0
pyflakes==0.9.2
Pygments==2.0.2
PyICU==1.9.2+xy.1
PyJWT==1.3.1.dev2
pylint==1.4.3
pyMinuit==1.2.1
PyOpenGL==3.1.0
PyOpenGL-accelerate==3.1.0
pyOpenSSL==0.15.1
pyparsing==2.0.3
PyQt4==4.11.3
pyreadline==2.0.6+xy.1
PyStemmer==1.3.0
python-dateutil==2.4.2
pytz==2015.4
pywin==0.3.1
pywin32==219
PyYAML==3.11
pyzmq==14.7.0
reportlab==3.2.0
requests==2.8.1
requests-oauthlib==0.5.0
rope==0.10.2
sampy==1.2.1
scandir==1.1.1.dev7
scikit-learn==0.17
scipy==0.15.1
scp==0.10.2
singledispatch==3.4.0.3
six==1.9.0
smart-open==1.3.2
snowballstemmer==1.2.1.dev1
Sphinx==1.3.2
sphinx-rtd-theme==0.1.8
sphinxcontrib-plantuml==0.6
spyder==2.3.5.2
SQLAlchemy==1.0.6
statsmodels==0.6.1
stop-words==2015.2.23.1
tables==3.2.0
Tempita==0.5.2
textmining==1.0
tornado==3.2.1
traceback2==1.4.0
ujson==1.33
unittest2==1.0.1
urllib3==1.10.4
veusz==1.23.1
virtualenv==13.0.3
virtualenvwrapper-win==1.2.1
ViTables==2.2a1
wheel==0.24.0
Whoosh==2.7.0
wincertstore==0.2
wsaccel==0.6.2
wxPython==2.8.12.1
wxPython-common==2.8.12.1
yappi==0.94
yg.lockfile==2.0
zc.lockfile==1.1.0
我还检查了我是否有自己的 io.py 版本,但它不存在。
我在使用此版本的 boto 时遇到了类似的错误消息:
>>> import boto
>>> boto.__version__
'2.20.1'
解决问题后(删除隐藏新版本的旧版本)我设法加载了 gensim:
>>> import boto
>>> boto.__version__
'2.39.0'
>>> import gensim
>>>
我建议您尝试将 boto 更新到更新的版本。
pip install boto --upgrade