[Python]python安裝與打包exe

首先 安裝python(版本不要求)
Python官網

可以參考此網頁安裝方式


安裝Selenium
1。開啟cmd
2。指向安裝python目錄
3。pip install selenium




下載

webdriver


Chrome & Firefox的webdriver傳送門





Firefox web driver

Chrome web driver


下載完成後,將zip裡檔案解壓縮到python目錄裡。





安裝 pyinstaller

1。在cmd

2。指向安裝python目錄

3。輸入 pip install pyinstaller







第一個範例:

開新網頁,新增一個按鈕,當按下按鈕後,會開啟google首頁並自輸填入搜詢的值。


首先
HTML

建立一個html,並新增button

<button onclick="open_exe('C:\\Users\\USER\\Desktop\\google.exe')">打开google</button>



PYTHON

建立新檔案,

並輸入

from selenium import webdriver

browser = webdriver.Chrome()

browser.get('https://www.google.com/')

element = browser.find_element_by_name("q");

element.send_keys('hello world');


儲存檔案並命名為 google.py。


pyinstaller 使用方法教學




py檔案要轉成exe:

1. 開啟cmd

2. 輸入 pyinstaller -F google.py 按enter







3.在python目錄裡,找dist資料夾,就可以看到轉的exe














[

轉exe過程錯誤訊息與解法

1。 from selenium import webdriver

^

IndentationError: unexpected indent


解法: 開啟要轉exe的檔案,再次檢視 發現 from selenium import webdriver的前面有一個空格

後來去掉空格後就正常可以往下執行。


2。 File "c:\users\user\python\lib\site-packages\PyInstaller\building\utils.py", line 660, in strip_paths_in_code

return code_func(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize,

TypeError: an integer is required (got type bytes)解法:更新版本
參考網站
如果您有理由認為自己在PyInstaller中發現了錯誤, 可以嘗試下載最新的開發版本。此版本可能具有PyPI尚未提供的修復或功能您可以從PyInstaller下載頁面下載最新的穩定版本和最新的開發版本
您也可以直接使用pip安裝最新版本的PyInstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
]






















































留言

這個網誌中的熱門文章

用List寫小算盤(先乘除後加減) C#

[C#]跨網頁自動傳值之Selenium grid 安裝與使用