Py2exe - 模块找不到

时间:2014-09-26 17:38:44

标签: python py2exe

我正在尝试从我的(2)py文件中创建一个exe文件。在一个文件中导入了bs4 - import bs4 当我尝试执行此脚本时:

setup(
    console = ['gui.py'],
    options = {
        'py2exe': {
            'packages': ["bs4"]
        }
    }
)

控制台返回:

    C:\Users\uživatel\PycharmProjects\mail_checker>setup.py py2exe
running py2exe
*** searching for required modules ***
Traceback (most recent call last):
  File "C:\Users\u×ivatel\PycharmProjects\mail_checker\setup.py", line 12, in <m
odule>
    'packages': ["bs4"]
  File "C:\Python27\lib\distutils\core.py", line 151, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run
    self.find_needed_modules(mf, required_files, required_modules)
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1306, in find_n
eeded_modules
    mf.import_hook(f)
  File "C:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "C:\Python27\lib\site-packages\py2exe\mf.py", line 136, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:\Python27\lib\site-packages\py2exe\mf.py", line 204, in find_head_pack
age
    raise ImportError, "No module named " + qname
ImportError: No module named bs4

所以我想我没有将setup.py写得正确。你能给我一个建议吗?感谢

1 个答案:

答案 0 :(得分:1)

解决方案:

问题可能是我通过easy_install安装了bs4(和xlsxwriter),它在site-packages文件夹中创建了* .egg文件。出于某种原因,Py2exe无法在site-packages中找到bs4。所以我尝试打开BeautifulSoup egg文件并将bs4文件夹复制到site-packages文件夹中,我对xlsxwriter做了同样的事情。

它有所帮助。程序正常运行。