我的目录结构如下所示:
- project
- server.py
- test-model (dir)
我的脚本如下所示:
@app.route("/spacy/entities", methods=['GET', 'POST'])
def spacy_entities():
import spacy
nlp = spacy.load('test-model') // also tried './test-model'
Can't find model 'test-model'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
我在《流浪汉》里写这个剧本
vagrant@homestead:~/Code/sideprojects/project$ pwd
/home/vagrant/Code/sideprojects/project
我尝试过的事情:
1. os.path.realpath('.') -> /home/vagrant/Code
2. os.path.realpath(__file__) -> /home/vagrant/Code/server.py
3. os.path.dirname(os.path.realpath(__file__)) -> /home/vagrant/Code
但是它应该是/home/vagrant/Code/sideprojects/project
,这样它就可以找到“测试模型”。我做错什么了
(我试图避免放置硬编码路径)
编辑:我试过:
path = os.path.dirname(os.path.realpath(__file__)) + '/sideprojects/project'
nlp = spacy.load(path + "/test-model")
Can't find model '/home/vagrant/Code/sideprojects/project/test-model'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
完全错误是:
File "server.py", line 40, in spacy_entities nlp = spacy.load(path + "/goal1") File "/home/vagrant/.local/lib/python3.6/site-packages/spacy/init.py", line 30, in load return util.load_model(name, **overrides) File "/home/vagrant/.local/lib/python3.6/site-packages/spacy/util.py", line 169, in load_model raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model '/home/vagrant/Code/sideprojects/project/test-model'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
创建一个新的py文件,比如
modelload.py
,然后在这个函数中创建一个函数,比如load_model
,加载空间模型示例代码
在路由脚本/
server.py
文件中,将此模型作为如下对象导入相关问题 更多 >
编程相关推荐