You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中无法加载GoogleNews-vectors-negative300.bin文件的求助

解决GoogleNews-vectors-negative300.bin导入时的FileNotFoundError问题

嗨,我来帮你搞定这个问题!你遇到的FileNotFoundError本质就是代码指定的路径下找不到目标文件,咱们一步步排查解决:

1. 确认文件是否真实存在

  • 先去你代码里写的./data文件夹里看看,有没有GoogleNews-vectors-negative300.bin这个文件?
  • 别忘了,这个文件足足有3.6G左右,你是不是完整下载了?如果下载中途中断,文件会缺失或损坏,也会触发这个错误。
  • 也可以用命令行验证:Windows用dir ./data,Linux/Mac用ls ./data,看看输出里有没有这个文件名。

2. 检查路径是否匹配当前工作目录

你用的是相对路径./data/GoogleNews-vectors-negative300.bin,这个路径是相对于你的Python脚本(或Jupyter Notebook)的当前工作目录的。很多时候问题就出在这:

  • 先在代码里加一行,打印当前工作目录,确认是不是你预期的项目根目录:
    import os
    print(os.getcwd())
    
  • 如果路径不对,要么把model_path改成绝对路径(比如Windows的C:/my_project/data/GoogleNews-vectors-negative300.bin,Linux/Mac的/home/username/my_project/data/GoogleNews-vectors-negative300.bin),要么把文件移到正确的相对路径下。

3. 核对文件名是否完全一致

  • 注意拼写和大小写!比如Linux/Mac系统对文件名大小写敏感,确保文件名是GoogleNews-vectors-negative300.bin,没有拼写错误(比如少个字母、多了空格)。
  • 另外,如果你下载的是压缩包(比如.bin.gz),一定要先解压出.bin文件再用,直接用压缩包会报找不到文件。

4. 排查权限问题(针对Linux/Mac)

如果是在Linux/Mac系统下,可能是文件权限不足导致无法读取:

  • 可以执行命令添加读取权限:
    chmod +r ./data/GoogleNews-vectors-negative300.bin
    

附你遇到的错误栈:

FileNotFoundError Traceback (most recent call last)
<ipython-input-16-04e6454088bc> in <module>
 1 from gensim.models.keyedvectors import KeyedVectors
 2 model_path = './data/GoogleNews-vectors-negative300.bin'
----> 3 w2v_model = KeyedVectors.load_word2vec_format(model_path, binary=True)
~\AppData\Local\conda\conda\envs\channel\lib\site-packages\gensim\models\keyedvectors.py in load_word2vec_format(cls, fname, fvocab, binary, encoding, unicode_errors, limit, datatype)
1434 return _load_word2vec_format(
1435 cls, fname, fvocab=fvocab, binary=binary, encoding=encoding, unicode_errors=unicode_errors,
-> 1436 limit=limit, datatype=datatype)
1437
1438 def get_keras_embedding(self, train_embeddings=False):
~\AppData\Local\conda\conda\envs\channel\lib\site-packages\gensim\models\utils_any2vec.py in _load_word2vec_format(cls, fname, fvocab, binary, encoding, unicode_errors, limit, datatype)
169
170 logger.info("loading projection weights from %s", fname)
-> 171 with utils.smart_open(fname) as fin:
172 header = utils.to_unicode(fin.readline(), encoding=encoding)
173 vocab_size, vector_size = (int(x) for x in header.split()) # throws for invalid file format
~\AppData\Local\conda\conda\envs\channel\lib\site-packages\smart_open\smart_open_lib.py in smart_open(uri, mode, **kw)
398 transport_params[key] = value
399
-> 400 return open(uri, mode, ignore_ext=ignore_extension, transport_params=transport_params, **scrubbed_kwargs)
401
402
~\AppData\Local\conda\conda\envs\channel\lib\site-packages\smart_open\smart_open_lib.py in open(uri, mode, buffering, encoding, errors, newline, closefd, opener, ignore_ext, transport_params)
298 buffering=buffering,
299 encoding=encoding,
-> 300 errors=errors,
301 )
302 if fobj is not None:
~\AppData\Local\conda\conda\envs\channel\lib\site-packages\smart_open\smart_open_lib.py in _shortcut_open(uri, mode, ignore_ext, buffering, encoding, errors)
457 #
458 if six.PY3:
-> 459 return _builtin_open(parsed_uri.uri_path, mode, buffering=buffering, **open_kwargs)
460 elif not open_kwargs:
461 return _builtin_open(parsed_uri.uri_path, mode, buffering=buffering)
FileNotFoundError: [Errno 2] No such file or directory: './data/GoogleNews-vectors-negative300.bin'

内容的提问来源于stack exchange,提问作者Abdul Wahab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:23:39