简体   繁体   中英

ModuleNotFoundError: No module named 'mysql' ; the <py-config> need to fix in .html

  • the python script can execute fine by itself
    (logically I pip install all stuff I need)
import mysql.connector
import webbrowser
import time
import pymysql

mydb = mysql.connector.connect(
  host="196.168.16.144",
  user="root",
  password="password123", 
  database="cloud_db",  
  auth_plugin='mysql_native_password'
)
                
mycursor = mydb.cursor()
mycursor.execute("SELECT P_TITLE,P_DESC  FROM webpage WHERE P_ID = 'en_1-01'")                       
                                         
myresult = mycursor.fetchall()

print(myresult)    

but run/execute in html faced ModuleNotFoundError: No module named 'mysql'

  • error message

Traceback (most recent call last):
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
.run(globals, locals)
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
coroutine = eval(self.code, globals, locals)
File "exec", line 4, in
ModuleNotFoundError: No module named 'mysql'

  • run py script in html
<html>
    <head>
      <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
      <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    </head>

  <body>
    <b><p>this is the info from sql</p></b>
    <br>
  
    <py-config>
      [[fetch]]
      files = ["./get_sql_where.py"]

      packages = ["mysql"]
    </py-config>

    <py-script src="get_sql_where.py">
        import pymysql
        import get_sql_where.py
      
    </py-script>
  </body>
</html>

Quesion: I already tried <py-config> but still facing ModuleNotFoundError, mysql.... how can I fix?


update:

I also tried to change the packages to ["mysql.connector"] but face the smae

<py-config>
  [[fetch]]
  files = ["./get_sql_where.py"]
  packages = ["mysql.connector"]
</py-config>
<py-script src="get_sql_where.py">
  import mysql.connector
  import get_sql_where.py
</py-script>
 

Have you install mysql module like this?

pip install mysql-connector-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM