当有两个模块作为隐藏模块导入时,如何执行隐藏导入命令?

2022-12-05 02:03:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从.py生成.exe,但遇到了两个模块的ModuleNotFoundError。 我尝试过这样做(尝试包括两个用逗号分隔的包):

pyinstaller -F --hidden-import "pkg_resources.py2_warn,win10toast" FileName.py

但它没有起作用。 是否有一种方法可以通过pyinstaller以隐藏方式导入这两种内容

如果您想查看代码:

from selenium import webdriver
import time
import win10toast
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from plyer import notification
from win10toast import ToastNotifier

i=1
while i<=20:
    ###
    toaster = ToastNotifier()
    toaster.show_toast("Initiating Session Number {}".format(i), "Marking Attendance", threaded=True,
                       icon_path=None, duration=6)  
    while toaster.notification_active():
        time.sleep(0.1)
    ###
    options = webdriver.ChromeOptions()
    options.add_argument('--ignore-ssl-errors=yes')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--allow-running-insecure-content')
    driver = webdriver.Chrome(options=options)

    driver.get('https://120.72.92.102:10443/remote/login?lang=en')
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "username")))

    username = driver.find_element_by_id("username")
    password = driver.find_element_by_id("credential")

    username.send_keys("subeer.singh")
    password.send_keys("ss)12345")

    driver.find_element_by_id("login_button").click()
    time.sleep(7)
    driver.close()

    ###
    toaster = ToastNotifier()
    toaster.show_toast("Done!", 'You will be online for next {} min'.format(i*30), threaded=True,
                       icon_path=None, duration=6)  
    while toaster.notification_active():
        time.sleep(0.1)
    ###
    i+=1
    time.sleep(1980)

if i>=20:
    toaster = ToastNotifier()
    toaster.show_toast("Done!", 'You will be online for next {} min'.format(i*30), threaded=True,
                       icon_path=None, duration=60)  
    while toaster.notification_active():
        time.sleep(0.1)
    exit()

Tags: fromimportbytimedriverseleniumusernamenotificationsleepelementoptionswebdriverwhiletoastertoastnotifier