【问题标题】:Using PyInstaller to Create EXE: EXE not working properly/not importing several modules使用 PyInstaller 创建 EXE:EXE 无法正常工作/未导入多个模块
【发布时间】:2015-05-24 02:13:59
【问题描述】:

我的 python 脚本应该导入以下内容:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import *
from selenium.webdriver.common.keys import Keys
from random import uniform
from xlutils.copy import copy
import xlrd
import wx
import os
import shutil
import time
from threading import *

当我使用 Pyinstaller 创建 EXE 时,EXE 无法正常工作。 python脚本运行完美。

这似乎是因为 Pyinstaller 没有包含某些模块。生成的警告文件显示以下内容未导入:

W: no module named xlrd.XL_CELL_EMPTY (top-level import by xlutils.margins)  
W: no module named pwd (top-level import by tarfile)  
W: no module named xlrd.XL_CELL_TEXT (top-level import by xlutils.margins)  
W: no module named readline (delayed import by pdb)  
W: no module named xlrd.XL_CELL_NUMBER (top-level import by xlutils.margins)  
W: no module named xlrd.open_workbook (top-level import by xlutils.margins)  
W: no module named _scproxy (conditional import by urllib)  
W: no module named _sysconfigdata (delayed import by distutils.sysconfig)  
W: no module named pwd (delayed import by getpass)  
W: no module named errorhandler (delayed import by xlutils.filter)  
W: no module named EasyDialogs (conditional import by getpass)  
W: no module named termios (top-level import by getpass)  
W: no module named grp (top-level import by tarfile)  
W: no module named xml.dom.XML_NAMESPACE (delayed import by xml.dom.pulldom)  
W: no module named gestalt (delayed import by platform)  
W: no module named org (top-level import by copy)  
W: no module named xlrd.XL_CELL_BLANK (top-level import by xlutils.margins)  
W: no module named fcntl (top-level import by tempfile)  
W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.minidom)  
W: no module named http (top-level import by selenium.selenium)  
W: no module named readline (delayed, conditional import by cmd)  
W: no module named elementtree (delayed, conditional import by xlrd.xlsx)  
W: no module named xlrd.open_workbook (conditional import by xlutils.margins)  
W: no module named java (delayed import by platform)  
W: no module named cl (delayed import by aifc)  
W: no module named posix (conditional import by __main__)  
W: no module named xmlparse (top-level import by pyexpat)  
W: no module named posix (conditional import by pyi_os_path)  
W: no module named java (conditional import by xml.sax._exceptions)  
W: no module named lxml (delayed, conditional import by xlrd.xlsx)  
W: no module named ElementC14N (top-level import by xml.etree.ElementTree)  
W: no module named xlrd.XL_CELL_TEXT (conditional import by xlutils.margins)  
W: no module named _emx_link (conditional import by os)  
W: no module named posix (conditional import by os)  
W: no module named xml.dom.DOMImplementation (top-level import by xml.dom.domreg)  
W: no module named xmltok (top-level import by pyexpat)  
W: no module named rourl2path (conditional import by urllib)  
W: no module named xlrd.cellname (top-level import by xlutils.margins)  
W: no module named pwd (delayed import by webbrowser)  
W: no module named xml.dom.EMPTY_NAMESPACE (top-level import by xml.dom.expatbuilder)  
W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.expatbuilder)  
W: no module named http (top-level import by selenium.webdriver.remote.remote_connection)  
W: no module named SOCKS (top-level import by ftplib)  
W: no module named _xmlplus (top-level import by xml)  
W: no module named guppy (top-level import by xlutils.filter)  
W: no module named http (top-level import by   selenium.webdriver.opera.webdriver)`  

这是否意味着正在导入 selenium 模块?我很难确定 exe 有什么问题。

【问题讨论】:

    标签: python selenium import pyinstaller


    【解决方案1】:

    我认为 Selenium 被认为是一个外部模块,因此您需要通过添加挂钩文件来指定它的路径。 看看这个tutorial,了解如何使用正确的路径设置挂钩文件。查看“使用外部模块”。

    【讨论】:

    • "hooks" 文件夹中已经有一个 selenium.py 文件(我没有添加)。我认为问题实际上可能是 xlrd/xlutils。该教程对如何制作钩子有点含糊。看起来我所要做的就是创建一个名为“hook-xlrd.py”的文件并包含以下语句: from PyInstaller.hooks.hookutils import collect_data_files dates = collect_data_files('xlrd')
    猜你喜欢
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2021-11-06
    相关资源
    最近更新 更多