无法调用不同文件夹中的模块

Unable to call for a module in a different folder

我克隆了 a repository of a Facebook research project 尝试 运行 python scripts/pipeline/interactive.py 启动一个程序,如 README 中所述。然而我总是有以下问题ModuleNotFoundError。事实上,我用 python 调用的文件调用了另一个不在同一目录中的文件。

这是完整的错误:

.
├── drqa
│   ├── pipeline
│   │   └── __pycache__
│   ...
...
├── scripts
│   ├── convert
│   ├── distant
│   ├── pipeline
│   ├── reader
│   └── retriever

这里是 interactive.py 脚本:

from termcolor import colored
from drqa import pipeline
from drqa.retriever import utils

我很担心,因为就 Facebook 研究团队所做的而言,这项工作可能是一项伟大的工作。我一定是漏掉了什么。

可能与我对README的这部分内容没有完全理解有关:

Note: requirements.txt includes a subset of all the possible required packages. Depending on what you want to run, you might need to install an extra package (e.g. spacy).

If you use the CoreNLPTokenizer or SpacyTokenizer you also need to download the Stanford CoreNLP jars and spaCy en model, respectively. If you use Stanford CoreNLP, have the jars in your java CLASSPATH environment variable, or set the path programmatically with:

import drqa.tokenizers drqa.tokenizers.set_default('corenlp_classpath', '/your/corenlp/classpath/*')

IMPORTANT: The default tokenizer is CoreNLP so you will need that in your CLASSPATH to run the README examples.

Ex: export CLASSPATH=$CLASSPATH:/path/to/corenlp/download/*.

If you do not already have a CoreNLP download you can run:

./install_corenlp.sh

Verify that it runs:

from drqa.tokenizers import CoreNLPTokenizer tok = CoreNLPTokenizer() tok.tokenize('hello world').words()  # Should complete immediately

For convenience, the Document Reader, Retriever, and Pipeline modules will try to load default models if no model argument is given. See below for downloading these models.

如果我确实安装了 ./install_corenlp.sh,我无法导出类路径,因为我不知道 /path/to/corenlp/download/* 是什么。

使用根目录“.”中的 python 调用您的脚本并添加到您的环境中:

$ export PYTHONPATH=".":$PYTHONPATH

这样python就可以知道'.'是一个 source root