[英]ConfigParser.NoSectionError: No section: 'locations' in Exe. Python
I created successfully an .exe file for my python code. 我为我的python代码成功创建了.exe文件。 As a .py file, it works like a charm.
作为.py文件,它的工作原理像一个超级按钮。 But when I try to run it from the exe version, I get error as follows:
但是,当我尝试从exe版本运行它时,出现如下错误:
Traceback (most recent call last):
File "CreateAS.pyw", line 14, in <module>
File "pulp\__init__.pyc", line 33, in <module>
File "pulp\pulp.pyc", line 103, in <module>
File "pulp\solvers.pyc", line 101, in <module>
File "pulp\solvers.pyc", line 59, in initialize
File "ConfigParser.pyc", line 532, in get
ConfigParser.NoSectionError: No section: 'locations'
How can I solve that? 我该如何解决?
Thanks in advance. 提前致谢。
Related Part of My code: 我的代码的相关部分:
And my Config file: 和我的配置文件:
Check if the section exists. 检查该部分是否存在。 If it does not - add it
如果没有-添加它
config = ConfigParser.ConfigParser()
if not config.has_section("locations"):
config.add_section("locations")
Ok. 好。 I found the solution.
我找到了解决方案。 There is a solvers.py in Pulp directory.
Pulp目录中有一个Solvers.py。 Inside it, I replaced the DIRNAME to the fullpath of the Pulp directory as follows:
在其中,我将DIRNAME替换为Pulp目录的完整路径,如下所示:
if __name__ != '__main__':
DIRNAME = r"C:\Python26\Lib\site-packages\PuLP-1.4.7-py2.6.egg\pulp"
config_filename = os.path.join(DIRNAME,
PULPCFGFILE) else: #run as a script
from pulp import __file__ as fname
DIRNAME = r"C:\Python26\Lib\site-packages\PuLP-1.4.7-py2.6.egg\pulp"
config_filename = os.path.join(DIRNAME,
PULPCFGFILE) cplex_dll_path, coinMP_path, gurobi_path, cbc_path, glpk_path = \
initialize(config_filename)
But for distribution purposes, You dont need to do the thing above. 但是出于分发目的,您不需要执行上述操作。 You should include pulp folder to the project.
您应该将纸浆文件夹包括到项目中。 And add the code below to the top of your project:
并将以下代码添加到项目顶部:
import sys
sys.path.append(r"C:\Python26\Lib\site-packages\PuLP-1.4.7-py2.6.egg\pulp")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.