5

I have postgres image: https://hub.docker.com/_/postgres I am trying to create the python extension with the following command:

create extension plpythonu

but it fail with the error:

psql:/docker-entrypoint-initdb.d/init.sql:1: ERROR:  could not open extension control file "/usr/share/postgresql/12/extension/plpythonu.control": No such file or directory

in my Dockerfile I try to install the package:

FROM postgres
RUN apt-get update -y
RUN apt install postgresql-plpython3-12

I get error:


Unable to locate package postgresql-plpython3-12

How can I extend the postgresql so that I can use python ?

1
  • What version of Debian? FYI, create extension plpythonu will install the Python 2 version. If you want the Python 3 version you will need to do create extension plpython3u. Commented Sep 24, 2020 at 14:15

1 Answer 1

8

I have found a solution to install plpython3 into my postgres container

FROM postgres

RUN apt-get update
RUN apt-get -y install python3 postgresql-plpython3-12
COPY pg-setup-scripts/init.sql /docker-entrypoint-initdb.d

and then in the entrypoint script


create extension plpython3u;

Sign up to request clarification or add additional context in comments.

4 Comments

I want to do this but in a macOS environment. So far it doesn't seem possible.
That's a postgres extension, postgresql does not run on MacOS natively.
I was trying to do the same thing as you with a container but I thought that the OS made a difference. Turns out that 'docker build' is done in a container so regardless of OS 'apt-get' runs fine. So your solution works and I built an image with python3/pandas/networkx that works just fine with a db I had running with a simpler postgres image.
Be sure to align the 12 in postgresql-plpython3-12 version with your psql version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.