平平无奇的清晨,冒着蒙蒙细雨,踏着破碎的枫叶,来到实验室开始Chapter10的学习~
一切都按部就班的进行着,突然,在运行以下示例时:
read_expr = nltk.sem.Expression.fromstring
lp = nltk.sem.Expression.fromstring
SnF = read_expr('SnF')
NotFnS = read_expr('-FnS')
R = read_expr('SnF -> -FnS')
prover = nltk.Prover9()
print(prover.prove(NotFnS, [SnF, R]))
遇到了一个错误:错误信息如下:
D:\Anaconda3\python.exe "E:/Python Practice/NLP/Chapter10.py"
Traceback (most recent call last):
File "E:/Python Practice/NLP/Chapter10.py", line 45, in <module>
print(prover.prove(NotFnS, [SnF, R]))
File "D:\Anaconda3\lib\site-packages\nltk\inference\api.py", line 37, in prove
return self._prove(goal, assumptions, verbose)[0]
File "D:\Anaconda3\lib\site-packages\nltk\inference\prover9.py", line 330, in _prove
self.prover9_input(goal, assumptions), verbose=verbose
File "D:\Anaconda3\lib\site-packages\nltk\inference\prover9.py", line 351, in _call_prover9
self._prover9_bin = self._find_binary("prover9", verbose)
File "D:\Anaconda3\lib\site-packages\nltk\inference\prover9.py", line 184, in _find_binary
verbose=verbose,
File "D:\Anaconda3\lib\site-packages\nltk\internals.py", line 690, in find_binary
name, path_to_bin, env_vars, searchpath, binary_names, url, verbose
File "D:\Anaconda3\lib\site-packages\nltk\internals.py", line 674, in find_binary_iter
path_to_bin or name, env_vars, searchpath, binary_names, url, verbose
File "D:\Anaconda3\lib\site-packages\nltk\internals.py", line 632, in find_file_iter
raise LookupError("\n\n%s\n%s\n%s" % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the prover9 file!
Use software specific configuration paramaters or set the PROVER9 environment variable.
Searched in:
- /usr/local/bin/prover9
- /usr/local/bin/prover9/bin
- /usr/local/bin
- /usr/bin
- /usr/local/prover9
- /usr/local/share/prover9
For more information on prover9, see:
<http://www.cs.unm.edu/~mccune/prover9/>
===========================================================================
Process finished with exit code 1
下面给出完整解决方法,参考文章附在文章结尾~
Step 1: 在官网下载Prover9
Prover9有GUI版本和Command Line版本。由于Command Line版本不提供Windows的版本,加之本人使用Windows系统,所以选择下载GUI版本的Prover9.地址为Prover9-Mace4 v05 (unm.edu)
就是下面这个Prover9-Mace4-v05-setup.exe 文件。
下载完成后安装即可,记住下载路径,之后会用到哦~
Step 2: 修改系统环境变量,增加一个环境变量如下。这里我修改了安装好的Prover9和bin的名字,不过不影响的,也可以不修改的哈
修改后, 重启编译器(我这里是PyCharm)然后再运行,顺利的话我们直接会得到结果~
没有成功的小伙伴和我继续往下看~
当我们重启后,发现原来的错误解决了,但是出现另一个错误:
PermissionError: [WinError 5]...
这个错误就是和访问权限有关,解决方法如下:
1. 关闭跟python相关的所有程序(这里是PyCharm),
2. 赋予用户对python“完全控制”的权限。
这里用的是Anaconda,在该文件目录下找到python.exe文件,右键属性,在Security一栏下,将Users的访问权限设置为Full control。
3。 重新打开PyCharm,再次运行程序。顺利执行!
(如果还是不行的话,再尝试把整个Anaconda文件夹的权限设置成Full control,进一步把PyCharm的权限进行相应设置,就可以啦~)
参考文章:
【问题和解决】NLTK was unable to find the prover9 file! - createMoMo - 博客园 (cnblogs.com)
三步解决python PermissionError: [WinError 5]拒绝访问的情况_python_脚本之家 (jb51.net)