Use Python installed with pyenv for PL / Python execution environment

Introduction

Python is becoming more and more a data analysis tool with the release of analysis packages such as chainer and tensorflow. It is attracting attention. There is a function called "PL / Python" that can use such Python as a function implementation language of PostgreSQL.

By default PL / Python uses the system Python. On the other hand, if you do not want to pollute the Python of the system, it seems that you may separate the Python environment with pyenv and put the analysis package.

Therefore, I investigated how to use Python installed by pyenv for the PL / Python execution environment.

1. Python installation with pyenv

PL / Python references libpython ~~ .so. Since the shared library is not installed by normal pyenv install Do the following:

CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.10

This is OK on the pyenv side

2. PL / Python compilation on PostgreSQL

PostgreSQL compiles from source. https://github.com/postgres/postgres From here, I think you can do git clone.

Then, with configure, do as follows.

./configure --prefix=/home/user/pgsql/pgsql9_5 --with-python=yes PYTHON=/home/user/.pyenv/versions/2.7.10/bin/python

You may or may not add the --prefix. The important thing is --with-python=yes When PYTHON=/home/user/.pyenv/versions/2.7.10/bin/python

If you don't add --with-python = yes, PL / Python won't compile in the first place. PYTHON = / home / user / .pyenv / versions / 2.7.10 / bin / python was installed with pyenv Specifies the location of Python binaries. PL / Python will then be compiled to use pyenv's Python.

When you execute configure, the following description will be written in the generatedMakefile.global.

python_includespec  = -I/home/user/.pyenv/versions/2.7.10/include/python2.7
python_libdir       = /home/user/.pyenv/versions/2.7.10/lib
python_libspec      = -L/home/user/.pyenv/versions/2.7.10/lib -lpython2.7

After that, if you make; make install PostgreSQL, the PL / Python execution environment will be Python installed with pyenv.

Supplement

I compiled the whole PostgreSQL, but should I compile only PL / Python?

Recommended Posts

Use Python installed with pyenv for PL / Python execution environment
Use smbus with python3 under pyenv environment
Building an Anaconda environment for Python with pyenv
Use multiple versions of python environment with pyenv
Use python installed with Pyenv with Sublime REPL of Sublime Text 3
Use Python in pyenv with NeoVim
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Create a Python execution environment for Windows with VScode + Remote WSL
I couldn't use tkinter with python installed by pyenv of anyenv
Use DeepL with python (for dissertation translation)
Use Anaconda-Python installed with pyenv from openFrameworks
Build a python virtual environment with pyenv
Prepare the execution environment of Python3 with Docker
Build python environment with pyenv on EC2 (ubuntu)
Create execution environment for each language with boot2docker
Use logger with Python for the time being
Wrap C with Cython for use from Python
Make OpenCV3 available from python3 installed with pyenv
Image Processing with Python Environment Setup for Windows
python development environment -use of pyenv and virtualenv-
Commands for creating a python3 environment with virtualenv
How to use tkinter with python in pyenv
Use jupyter-lab installed in python virtual environment (venv)
Use Python in Anaconda environment with VS Code
Wrap C ++ with Cython for use from Python
Build PyPy and Python execution environment with Docker
Build a python execution environment with VS Code
[Python] Use JSON with Python
Use mecab with Python3
Use DynamoDB with Python
Use Python 3.8 with Anaconda
Use python with docker
Python environment with docker-compose
Install python with pyenv
Virtual environment with Python 3.6
Python environment for projects
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Create a virtual environment with Anaconda installed via Pyenv
Build a python environment for each directory with pyenv-virtualenv
Building an environment for natural language processing with Python
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Install the latest Python from pyenv installed with homebrew
Use AWS SDK for Python (boto) under Proxy environment
Use Anaconda in pyenv environment
Install Python environment with Anaconda
Manage python environment with virtualenv
Use Twitter API with Python
Use TUN / TAP with Python
Build python3 environment with ubuntu 16.04
Python environment construction For Mac
Prepare python3 environment with Docker
Build python environment with direnv
Python3 environment construction (for beginners)
Execution time measurement with Python With
Reinstall python with pyenv with -fPIC
[For organizing] Python development environment
python with pyenv and venv
Use subsonic API with python3
Get a clean Python development environment with pyenv + pipx + Poetry