リンク内容
↑
こちらのサイトのプログラムを実際に実行したいのですが、2行目の「import webview」にエラーが出てしまい、実行できないです。
実行させるプログラム
import sys import webview class Api: def __init__(self): self.name = "js_api" def my_exec(self): response = { 'message': 'Pythonバージョン: {0}'.format(sys.version) } return response def get_html(): html_str = """ <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <style> #response-container { display: none; padding: 3rem; margin: 2rem 2rem; font-size: 100%; border: 2px dashed #ccc; } label { margin-left: 0.3rem; margin-right: 0.3rem; } button { display: inline-block; text-decoration: none; color: #FFF; width: 140px; height: 80px; font-weight:bold; line-height: 80px; border-radius: 50%; text-align: center; overflow: hidden; background-image: linear-gradient(45deg, #709dff 0%, #91fdb7 100%); transition: .4s; } button:hover { -webkit-transform: rotate(10deg); transform: rotate(10deg); } </style> </head> <body> <h1>Javascript API</h1> <p id='pywebview-status'><i>pywebview</i> is not ready</p> <button onClick="exec_python()">Python実行</button><br/> <div id="response-container"></div> <script> window.addEventListener('pywebviewready', function() { var container = document.getElementById('pywebview-status') container.innerHTML = '<i>pywebview</i> is ready' }) function get_return_from_python(response) { var container = document.getElementById('response-container') container.innerText = response.message container.style.display = 'block' } function exec_python() { pywebview.api.my_exec().then(get_return_from_python) } </script> </body> </html> """ return html_str if __name__ == '__main__': #GUI html = get_html() #関数 api = Api() window = webview.create_window('JavaScriptからPythonを実行する', html=html, js_api=api, height=400) webview.start()
エラー
Traceback (most recent call last): File "sample.py", line 2, in <module> import webview ModuleNotFoundError: No module named 'webview'
pipやcondaでインストールしたのですが失敗します。
アドバイスを頂けると嬉しいです。よろしくお願いします。
環境:Mac、Anaconda、VSCode

回答1件
あなたの回答
tips
プレビュー