python - 我找不到答案如何从包含所有依赖库的 py 文件中制作 exe
问题描述
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class UntitledTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_untitled_test_case(self):
driver = self.driver
driver.get("https://example.com")
driver.find_element_by_xpath("(//button[@type='button'])[13]").click()
driver.find_element_by_xpath("(//button[@type='button'])[26]").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
我希望将此 python 文件转换为 exe。我尝试过使用 pyinstaller,但它不会编译像 selenium 这样的依赖项,即使使用 --onefile 参数也是如此。有没有办法用这个 python 脚本制作一个 .exe 文件?我已经进行了如下搜索,但我找不到任何明确的答案。
https://datatofish.com/executable-pyinstaller/
PS 我不想在“编译列表”中手动包含包,因为我有数百个 py 文件要转换。
谢谢。
解决方案
看看这个以前用多种解决方案回答过的问题,而不仅仅是使用 pyinstaller:
推荐阅读
- javascript - page_action click 不起作用,而 browser_action click 在 Chrome 扩展中起作用?
- html - Overflow:hidden 隐藏伪元素本身
- c# - 同步调用异步嵌套方法 - 异步会沿着路径工作吗?
- java - 使用分页时,在spring jpa本机查询中,“select count(*) from”被“select count(where)”替换
- r - 如何从模块返回闪亮输入的值,在主应用程序中处理这些输入并将信息发送到模块进行输出?
- swift - 如何在iOS中Highcharts瀑布图中的条之间隐藏破折号
- google-apps-script - 如何使用 app-script 通过后台进程重新加载 gmail 插件
- excel - 如何在字符串和变量中加粗字符串
- javascript - Node.js - 节点邮件程序:不接受用户名和密码
- python - How to name dataframes dynamically in Python?