简体   繁体   English

py2exe在其他路径中找不到模块

[英]py2exe can't find module if in different path

I'm trying to create an exe using the following config options - 我正在尝试使用以下配置选项创建一个exe-

setup(name='tidalZabbix',
      version=version,
      description='python module to submit job stats to Zabbix',
      url='',
      author='Me',
      author_email='me@company.com',
      license='',
      # folders with functions
      console=[{'script': os.path.join(BASE_DIR, 'code/tidal_zabbix.py')}],
      options={
          'build': {'build_base': 'c:/tidalZabbix/build'},
          'py2exe':
              {
                  'dist_dir': 'c:/tidalZabbix',
                  'includes': ['decimal'],
              }
      }
      )

I have a separate module in the code directory called code/ZabbixSender.py 我在代码目录中有一个单独的模块,称为code/ZabbixSender.py

when I try to run python setup.py py2exe I get the following error - 当我尝试运行python setup.py py2exe时,出现以下错误-

The following modules appear to be missing
['ZabbixSender']

If I move the ZabbixSender.py to the same location as my setup.py the build works fine. 如果将ZabbixSender.py移到与setup.py相同的位置,则构建可以正常进行。

ie. 即。 if I do this: 如果我这样做:

'includes': ['decimal', 'code.ZabbixSender'],

or 要么

'includes': ['decimal', 'ZabbixSender'],

It still doesn't find the Module. 它仍然找不到模块。

I'd like to think this is bad error reporting by p2exe. 我想认为这是p2exe的错误报告。

The solution has nothing to do with my py2exe config but in the tidal_zabbix.py script being called. 该解决方案与我的py2exe配置无关,但与tidal_zabbix.py脚本有关。

This was the "incorrect" import 这是“不正确”的导入

from ZabbixSender import ZabbixPacket, ZabbixSender

As soon as I modified it to this - 我将其修改为

from code.ZabbixSender import ZabbixPacket, ZabbixSender

The build worked with no issues. 该版本没有任何问题。 Odd though considering running directly from python had no issues with the code. 奇怪的是,尽管考虑直接从python运行没有代码问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM