python - plpython3u Docker Postgres 安装 3rd
问题描述
我有点迷失如何在 plpython3u 存储过程中使用 python 库。我有下面的泊坞窗文件。我可以使用 plpython3u,但在存储的 plpython3u 过程中编写以下语句失败:
导入请求
我想我必须告诉 plpython3u 第 3 方库的安装位置,因为我不知道该怎么做。
下面列出的是我的 docker 文件的副本
FROM postgres:13.2
RUN apt-get update && apt-get install -y postgresql-13-mysql-fdw && apt-get install -y postgresql-plpython3-13 && apt-get -y install python3-pip
RUN pip3 install requests
这是我的存储过程的示例
CREATE OR REPLACE FUNCTION client_billing.process_sync_date(in_sync_date_id bigint) RETURNS void AS
$BODY$
import requests
try:
response = requests.get("http://www.google.com")
plpy.debug(response)
except requests.exceptions.RequestException as e: # This is the correct syntax
plpy.debug(requesterror.RequestError(e))
$BODY$
LANGUAGE plpython3u VOLATILE
COST 100;
ALTER FUNCTION client_billing.process_sync_date(in_sync_date_id bigint) OWNER TO postgres;
注意我回到 pgadmin 如下:
ERROR: ModuleNotFoundError: No module named 'requests'
CONTEXT: Traceback (most recent call last):
PL/Python function "process_sync_date", line 2, in <module>
import requests
PL/Python function "process_sync_date"
SQL state: 38000
解决方案
推荐阅读
- c++ - 在 Openmp 中有没有办法找出主线程分配到的位置?
- c - 为什么我的数组显示不加起来?
- powershell - 无法获取工作表类的粘贴属性
- prolog - 谓词顺序更改导致无限循环
- python - 使用 selenium 和 urllib 请求自动抓取 pdf 数据
- java - 如何在 Java 中将其内容是单个字节的十六进制值的字符串 [] 转换为字节 []
- php - APACHE 权限已全部设置,但仍然没有权限 (*已解决*)
- vue.js - 如何动态更改滑块图像
- protocol-buffers - 如何在 GRPC 协议缓冲区中使用版本控制
- pine-script - 如何在行尾打印“x”的当前值作为标签?