【问题标题】:Python script fails to import mysql.connector when run from Lua从 Lua 运行时,Python 脚本无法导入 mysql.connector
【发布时间】:2022-01-07 19:41:59
【问题描述】:

我有一个 Python 脚本,我尝试使用以下 Nginx 位置块从 Openresty/Lua 运行:

location / {
    access_by_lua_block {
    ngx.req.read_body()
    local request = ngx.req.get_body_data()
    io.popen("python3 /www/test.py '" .. request .. "'")
        }
}

脚本内容:

#!/usr/bin/python3
import sys
import json
(...)

-- 从命令行运行 => 有效

-- 从 Lua 运行 => 工作

但是,如果我尝试导入 mysql.connector,它不再可以从 Lua 工作,尽管它仍然可以从命令行:

#!/usr/bin/python3
import sys
import json
import mysql.connector
(...)

-- 从命令行运行 => 有效

-- 从 Lua 运行 => 失败/记录:

Traceback (most recent call last):
  File "/www/test.py", line 4, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'

那么我在这里错过了什么?

【问题讨论】:

    标签: python lua mysql-connector openresty


    【解决方案1】:

    在这里找到答案:https://askubuntu.com/questions/1014947/mysql-connector-python-importerror-no-module-named-mysql

    应该apt-get install python3-mysql.connector (即不仅仅是pip install mysql-connector-python3

    【讨论】:

      猜你喜欢
      • 2015-08-30
      • 1970-01-01
      • 2021-06-08
      • 2021-01-17
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      相关资源
      最近更新 更多