【问题标题】:PyInstaller throws error module not foundPyInstaller 抛出错误模块未找到
【发布时间】:2021-11-28 22:10:36
【问题描述】:

我正在尝试使用命令使用 pyinstaller 将 .py 转换为 exe

pyinstaller --onefile app.py

当我运行exe文件时,它会抛出错误

from bs4 import BeautifulSoup as bs

在这一行,找不到模块

有人可以帮助我在我的文件中使用 python 包

from bs4 import BeautifulSoup as bs
from csv import reader
import json, requests, time, gspread, sys, re, calendar, traceback, string, unidecode, datetime
from oauth2client.service_account import ServiceAccountCredentials

pyinsatller 无法在没有导入 exe 正常工作的情况下加载 python 包

删除 python 导入使其 100% 工作

我正在使用 python 2.7

任何帮助将不胜感激

【问题讨论】:

    标签: python python-2.7 pyinstaller


    【解决方案1】:

    Pyinstaller 可能对您创建的别名有问题。尝试添加 --hidden-import "bs4"

    例如:

        pyinstaller --noconfirm --onefile --console --hidden-import "bs4"  "./app.py"
    

    另外,请确保 pyinstaller 使用正确的解释器进行打包。如果您有其他 python 解释器,它们可能会干扰。你可以通过运行得到python可执行文件的完整路径

    import sys
    print(sys.executable)
    

    有一个用于 pyinstaller 的开源 GUI:

    pip install auto-py-to-exe
    

    要运行,只需激活您的 virtualenv 或 conda 环境并在终端中运行:

    auto-py-to-exe
    

    【讨论】:

      【解决方案2】:

      试试这个它对我有用:-

      pyinstaller --noconfirm --onefile --console --hidden-import "beautifulsoup4"  "app.py"
      

      【讨论】:

        猜你喜欢
        • 2020-11-27
        • 1970-01-01
        • 2017-03-02
        • 1970-01-01
        • 2021-01-02
        • 1970-01-01
        • 2018-02-26
        • 2016-01-27
        • 2018-02-19
        相关资源
        最近更新 更多