Search code examples
pythonpy2exe

Py2exe - module does not find


I'm trying to make an exe file from my (2) py files. In one file is bs4 imported - import bs4 When I try to execute this script:

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

the console returns:

    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

So I suppose that I haven't setup.py written correct. Could you give me an advice? Thanks


Solution

  • SOLUTION:

    The problem was probably that I have installed bs4 (and xlsxwriter) by easy_install which creates *.egg files in site-packages folder. Py2exe couldn't find bs4 in site-packages for some reason. So I tried to open BeautifulSoup egg file and copy bs4 folder into site-packages folder, I did the same with xlsxwriter.

    It helped. Program works properly.