gojomo的回答是对的
gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin.gz", binary=True)
尝试升级gensim的所有依赖项(例如smart_open),如果仍然出现以下错误
pip install --upgrade gensim
文件“/home/liangn/PythonProjects/DeepRecommendation/Algorithm/Word2Vec.py”,第 18 行,在 init 中
self.model = gensim.models.KeyedVectors.load_word2vec_format(w2v_path, binary=True)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/gensim/models/keyedvectors.py”,第 191 行,load_word2vec_format,utils.smart_open(fname) 为 fin:
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第 138 行,在 smart_open
return file_smart_open(parsed_uri.uri_path, mode)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第 642 行,在 file_smart_open
return compression_wrapper(open(fname, mode), fname, mode)
文件“/home/liangn/PythonProjects/venvLiang/lib/python2.7/site-packages/smart_open/smart_open_lib.py”,第630行,在compression_wrapper中
return make_closing(GzipFile)(file_obj, mode)
文件“/usr/lib64/python2.7/gzip.py”,第 94 行,在 init 中
fileobj = self.myfileobj = builtin.open(filename, mode or 'rb')
TypeError:强制转换为 Unicode:需要字符串或缓冲区,找到文件