我正在尝试从我的(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。你能给我个建议吗?谢谢

最佳答案

解:

问题可能是我已经通过easy_install安装了bs4(和xlsxwriter),该文件在site-packages文件夹中创建* .egg文件。由于某些原因,Py2exe在site-packages中找不到bs4。因此,我尝试打开BeautifulSoup egg文件并将bs4文件夹复制到site-packages文件夹,我对xlsxwriter进行了同样的操作。

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

关于python - py2exe-模块找不到,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26065280/

10-11 06:20