ConfigParser.NoSectionError:没有部分:“位置”;在执行中。 Python

发布于 2024-10-25 07:18:07 字数 757 浏览 2 评论 0 原文

我成功地为我的 python 代码创建了一个 .exe 文件。作为一个 .py 文件,它的工作方式就像一个魅力。但是当我尝试从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'

我该如何解决这个问题?

提前致谢。

我的代码的相关部分:

在此处输入图像描述

和我的配置文件:

下载配置

I created successfully an .exe file for my python code. As a .py file, it works like a charm. But when I try to run it from the exe version, I get error as follows:

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:

enter image description here

And my Config file:

Download the Config

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奶茶白久 2024-11-01 07:18:07

检查该部分是否存在。如果没有 - 添加它

config = ConfigParser.ConfigParser()
if not config.has_section("locations"):
    config.add_section("locations")

Check if the section exists. If it does not - add it

config = ConfigParser.ConfigParser()
if not config.has_section("locations"):
    config.add_section("locations")
断桥再见 2024-11-01 07:18:07

好的。我找到了解决方案。 Pulp 目录中有一个solvers.py。在其中,我将 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)

但出于分发目的,您不需要执行上述操作。您应该将pulp 文件夹包含到项目中。并将以下代码添加到项目的顶部:

import sys
sys.path.append(r"C:\Python26\Lib\site-packages\PuLP-1.4.7-py2.6.egg\pulp")

Ok. I found the solution. There is a solvers.py in Pulp directory. Inside it, I replaced the DIRNAME to the fullpath of the Pulp directory as follows:

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文