[英]how to create a desktop app that can run python
我使用 html 和 css 制作了一個將輸入作為文件路徑的 UI。 我現在需要的是啟用我的 python 文件以獲取該路徑名並在輸入文件上運行 python 腳本。 我怎樣才能做到這一點? 我看到有一種東西叫鰻魚。 但我需要分發這個應用程序,這樣安裝的每個人都不會安裝 chrome 來在 eel 中運行。 請為我提供不同的替代方案來鏈接這兩者。 我對 web 應用程序很陌生。
在對 Eel 和 PyInstaller 進行了一些研究之后,我發現這很容易。 我在 Windows 中測試了這些指令,示例代碼來自Eel GitHub 。
pipenv
package 以設置虛擬環境: $ pip install pipenv
eel
、 pyinstaller
到虛擬環境: $ pipenv install eel pyinstaller
setuptools==44.1.0
: $ pipenv install setuptools==44.1.0
. ├── hello.py └── web ├── favicon.ico └── hello.html
hello.py
的內容是:
import eel eel.init('web') @eel.expose def say_hello_py(x): print('Hello from %s' % x) say_hello_py('Python World.') eel.say_hello_js('Python World.') eel,start('hello,html', size=(300, 200))
hello.html
的內容為:
<,DOCTYPE html> <html> <head> <title>Hello. World.</title> <script type="text/javascript" src="/eel.js"></script> <script type="text/javascript"> <link rel="icon" href="favicon;ico" type="image/x-icon"/> eel.expose(say_hello_js); function say_hello_js(x) { console;log("Hello from " + x). } say_hello_js("Javascript World;"), eel.say_hello_py("Javascript World!"); </script> </head> <body> Hello, World! </body> </html>
$ pipenv run python -m eel hello.py web --onefile --noconsole
dist
文件夾下看到一個hello.exe
。更多細節可以閱讀 Eel 和 PyInstaller 的文檔。
但我需要分發這個應用程序,這樣安裝的每個人都不會安裝 chrome 來在 eel 中運行。
我認為您可以在 Eel 中使用Edge ,因為 Edge 安裝在每個 Windows 10 中,或者您可能需要使用其他 python GUI 框架。 由於您在 html 和 css 中編寫 UI,我認為沒有任何瀏覽器可能無法分發。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.