gpt4 book ai didi

python - 没有这样的文件或目录 : 'GoogleNews-vectors-negative300.bin'

转载 作者:行者123 更新时间:2023-12-05 05:47:35 28 4
gpt4 key购买 nike

我有这段代码:

import gensim
filename = 'GoogleNews-vectors-negative300.bin'
model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)

这是我的文件夹组织: image of my folder tree that shows that the .bin file is in the same directory as the file calling it, the file being ai_functions

但遗憾的是,我不确定为什么会出现错误提示找不到它。顺便说一句,我检查过,我确定文件没有损坏。有什么想法吗?

完整回溯:

  File "/Users/Ile-Maurice/Desktop/Flask/flaskapp/run.py", line 1, in <module>
from serv import app
File "/Users/Ile-Maurice/Desktop/Flask/flaskapp/serv/__init__.py", line 13, in <module>
from serv import routes
File "/Users/Ile-Maurice/Desktop/Flask/flaskapp/serv/routes.py", line 7, in <module>
from serv.ai_functions import checkplagiarism
File "/Users/Ile-Maurice/Desktop/Flask/flaskapp/serv/ai_functions.py", line 31, in <module>
model = gensim.models.KeyedVectors.load_word2vec_format(filename, binary=True)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/gensim/models/keyedvectors.py", line 1629, in load_word2vec_format
return _load_word2vec_format(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/gensim/models/keyedvectors.py", line 1955, in _load_word2vec_format
with utils.open(fname, 'rb') as fin:
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 188, in open
fobj = _shortcut_open(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 361, in _shortcut_open
return _builtin_open(local_path, mode, buffering=buffering, **open_kwargs)
FileNotFoundError: [Errno 2] No such file or directory: 'GoogleNews-vectors-negative300.bin'

最佳答案

Python 进程将认为事件的“当前工作目录”,因此将用作普通相对文件名 GoogleNews-vectors-negative300.bin 的预期位置,这将取决于您如何启动 Flask。

您可以打印出目录以确保——查看How do you properly determine the current script directory? 中的一些方法– 但我怀疑它可能只是 /Users/Ile-Maurice/Desktop/Flask/flaskapp/ 目录。

如果是这样,您可以使用相对于上述目录的路径相对引用您的文件...

serv/GoogleNews-vectors-negative300.bin

...或者您可以使用完整的“绝对”路径...

/Users/Ile-Maurice/Desktop/Flask/flaskapp/serv/GoogleNews-vectors-negative300.bin

...或者您可以将文件向上移动到它的父目录,这样它就在您的 Flask run.py 旁边。

关于python - 没有这样的文件或目录 : 'GoogleNews-vectors-negative300.bin' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70973660/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com