Reputation: 1054
I need to install plpython because I'm getting the error
could not access file "$libdir/plpython2": No such file or directory
when trying to do python manage.py migrate. I have seen different suggestions on how to install this package but none works for me because I need to be using python version 2.7 (some people suggested installing python 3.2) and I cannot run sudo apt-get install ... because I have to be working on a mac.
I have tried running
CREATE LANGUAGE plpython2u;
but I got the error
ERROR: could not access file "$libdir/plpython2": No such file or directory
Also, I have tried pip/brew install plpython
. But no result. Any suggestions?
Upvotes: 13
Views: 3441
Reputation: 1205
Working with this in several environments I found it's easier to run postgres in a Docker container using a modified postgres image. What follows are simple steps for doing that.
First install Docker.
Second create a directory to contain your dB and open a terminal in that directory.
Third build the desired image. Create a Dockerfile
that tells Docker what the image should look like. This is what I use to specify that I want a container running a postgres db and to include python3 as a procedural language extension (though you could specify python2). Note that I specify the version of postgres I want (13) and the compatible plpython3 (also 13).
I also include a reference to a 'requirements' file (see next step):
FROM postgres:13
RUN apt-get update
RUN apt-get -y install python3 postgresql-plpython3-13
RUN apt-get -y install python3-pip
RUN apt-get clean && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/*
# Requirements installation
COPY requirements_dockerbuild13.txt /tmp/
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --requirement /tmp/requirements_dockerbuild13.txt
Fourth, is an optional step to specify any additional libraries/packages/modules of interest. Those can be put in a 'requirements.txt' file. If you don't have any requirements just delete the line referring to them in the Dockerfile
. If you do have requirements then create a 'requirements.txt' file. In my case I wanted the image to also include 'pandas' and 'networkx'. My file looks like (yes, two lines of text):
pandas>=1.3.5
networkx>=2.0
Fifth, at the command line in your terminal run docker build -t xxx .
. The -t xxx
is the name you give to the image and the .
means the Dockerfile is in the current directory. Voila you've now have a postgres image named 'xxx' that contains postgres/python3/plpython3/pandas/networkx In my case the tag I used was 'postgresql-plpython3-13'.
To use the image you launch it using docker-compose up -d
and that command will launch an image in accordance with the docker-compose.yml
located in the directory. Yes, one more text file to create. Mine looked like this:
version: "3"
services:
postgres:
image: postgresql-plpython3-13 <--- name of the image just created
container_name: cain_db <--- arbitrary name of container running image
command: ["-c", "logging_collector=on","-c", "log_statement=all"]
volumes:
- ./caindata:/var/lib/postgresql/data <--- *comments below*
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=cain_data <---- name of db
ports:
- 5566:5432 <--- making the db available on port 5566 instead of 5432
volumes:
caindata: <--- name of the volume
That docker-compose file makes docker run a container named cain_db with the postgres image you created running inside it. That db can be connected to on port 5566 a port I chose to be different from the default postgres port (I could have used 5432). The db will be named 'cain_data' and here's the important bit: the db will be in a folder in the current directory named 'caindata' as opposed to /var/lib/postgresql/data which is where MacOS would put it.
To shut down the container use docker-compose down --remove-orphans
. The database will persist and when you launch docker-compose up -d
everything will be as it was when you shut down.
Recap:
docker-compose up
, shut down with docker-compose down
Additional notes:
Dockerfile
, a file called requirements.txt
, a file called docker-compose.yml
, and a sub-directory with the db.Upvotes: 0
Reputation: 51
Many thanks to @facetoe; sadly as others have said this commit took out the functionality https://github.com/Homebrew/homebrew-core/commit/c55743ce2e993d3407a7f7932abfe4910a25f953#diff-c290cd53a44f82f9ba1f4d59d9f90140. Ultimately i want the latest just with python; the quickest way for me was:
git clone https://github.com/Homebrew/homebrew-core.git
cd homebrew-core/
vi Formula/postgresql.rb
here you need to add into the install block the environment variable for python and --with-python
into the args listing. My diff on current master is:
@@ -38,6 +38,7 @@ class Postgresql < Formula
def install
ENV.prepend "LDFLAGS", "-L#{Formula["[email protected]"].opt_lib} -L#{Formula["readline"].opt_lib}"
ENV.prepend "CPPFLAGS", "-I#{Formula["[email protected]"].opt_include} -I#{Formula["readline"].opt_include}"
+ ENV["PYTHON"] = which("python3")
args = %W[
--disable-debug
@@ -56,6 +57,7 @@ class Postgresql < Formula
--with-libxslt
--with-openssl
--with-pam
+ --with-python
--with-perl
--with-tcl
--with-uuid=e2fs
Then finally you want to install it with:
brew install --build-from-source ./Formula/postgresql.rb
sudo install_name_tool -change @rpath/Python3.framework/Versions/3.8/Python3 /usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/Python /usr/local/lib/postgresql/plpython3.so
brew services start postgresql
Upvotes: 1
Reputation: 598
(macOS Catalina 10.15.5, Homebrew 2.3.0)
The voted solution does not work with recent versions of Homebrew, which does not support options anymore, see https://github.com/Homebrew/homebrew-core/issues/31510.
> brew reinstall [email protected] --with-python
...
Error: invalid option: --with-python
Fortunately, there is petere / homebrew-postgresql
I first updated the XCode command tools, in order to avoid this error:
configure: error: header file <perl.h> is required for Perl
with
> sudo rm -rf /Library/Developer/CommandLineTools
> sudo xcode-select --install
And then
> brew tap petere/postgresql
> brew reinstall petere/postgresql/[email protected]
brought plpython2 back to life for me.
Upvotes: 3
Reputation: 393
I quickly create a tap formula for the latest postgresql (11.2), add a --with-python option to compile options. So far it's work. No binary version, only compile from source. To use it:
brew tap indlin/postgresql-py
brew install postgresql-py
If I understand correctly, this is the official path for change options in brew (create your own tap formula). I don't understand why they do it???
Upvotes: 4
Reputation: 729
Ugh, this was a real pain as they have removed the with-python@2
option. I managed to get it installed with the following steps:
git clone https://github.com/Homebrew/homebrew-core.git
cd homebrew-core/
git checkout c2c0659f5a2e5be9c54c214e5aa19a2fe2cdc374
brew install --build-from-source ./Formula/[email protected] --with-python@2
brew services restart [email protected]
Probably there is a better way but this worked for me.
Upvotes: 2
Reputation: 1054
If anybody has the same problem, I fixed this by uninstalling postgres and installing it using brew install postgres --with-python
Upvotes: 13