plpython3u anaconda environment

58 views Asked by At

I am trying to use an anaconda environment inside my plpython3u function in postgres 15. Here is what I tried so far:

DROP FUNCTION use_anaconda_env();

CREATE OR REPLACE FUNCTION use_anaconda_env()
RETURNS text
LANGUAGE plpython3u
AS $$
import os

# Set the PYTHONHOME environment variable to point to your Anaconda environment
os.environ['PYTHONPATH'] = '/root/miniconda3/envs/py39'

# Your Python code here
# For example, check the Python version
import sys
python_version = sys.version

# Return the Python version
return python_version
$$;


SELECT * FROM use_anaconda_env();

Output

"3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]"

The function works but the output is the path of the python in the system and not in the anaconda environment. How can I set the path to my anaconda environment?

0

There are 0 answers