Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python FileNotFoundError:[Errno 2]没有这样的文件或目录:mallet路径_Python_Windows_File_Path_Mallet - Fatal编程技术网

Python FileNotFoundError:[Errno 2]没有这样的文件或目录:mallet路径

Python FileNotFoundError:[Errno 2]没有这样的文件或目录:mallet路径,python,windows,file,path,mallet,Python,Windows,File,Path,Mallet,所以这段代码以前是有效的,现在我得到了这个错误-请帮助:( mallet_路径='C:/mallet/mallet-2.0.8/bin/mallet.bat' ldamallet\u test=gensim.models.wrappers.ldamallet(mallet\u path,corpus=bow\u corpus\u test,num\u topics=20,id2word=dictionary\u test)这是因为Mallet的主目录设置不正确。即使您将二进制文件集的路径设置为

所以这段代码以前是有效的,现在我得到了这个错误-请帮助:(

mallet_路径='C:/mallet/mallet-2.0.8/bin/mallet.bat'

ldamallet\u test=gensim.models.wrappers.ldamallet(mallet\u path,corpus=bow\u corpus\u test,num\u topics=20,id2word=dictionary\u test)
这是因为Mallet的主目录设置不正确。即使您将二进制文件集的路径设置为变量,也必须定义包含Mallet所在位置的源的环境变量:

import os
from gensim.models.wrappers import LdaMallet

os.environ['MALLET_HOME'] = 'C:\\mallet\\mallet-2.0.8'

mallet_path = 'C:\\mallet\\mallet-2.0.8\\bin\\mallet'
ldamallet_test = gensim.models.wrappers.LdaMallet(mallet_path, corpus=bow_corpus_test, num_topics=20, id2word=dictionary_test)
请注意,您不需要添加
.bat
扩展名,因为Windows应该以本机方式执行,因为它知道这是一个批处理文件。最后,您应该使用双反斜杠(
\\
)用于Windows中的路径分隔符。根据您使用的Windows版本不执行此操作可能会导致意外行为。如果您想避免麻烦,请尝试使用将为您提供正确路径分隔符的操作系统:

mallet_path = os.path.join('C:', 'mallet', 'mallet-2.0.8', 'bin', 'mallet')
通过CMD shell执行时,可以假定文件扩展名为“.bat”(例如,使用
subprocess.Popen
shell=True
)因为它在
PATHEXT
环境变量中。否则不能假定它。这是一种shell行为,不是Windows的常规行为。
CreateProcessW
支持通过
ComSpec
shell直接执行批处理脚本,但必须包含“.bat”或“.cmd”扩展名。否则,它只假定为“.exe”作为文件扩展名,并尝试以二进制图像的形式执行找到的任何文件。