2

I've got Anaconda installed on a Ubuntu and would like to use some of it's modules in PL/Python. However, every time I call scipy, it errors with ImportError: No module named scipy.stats.

How do I get the Anaconda to work with PL/Python?

UPDATED: Below is the code & the error

CREATE OR REPLACE FUNCTION hdi_bars( numerator integer, denominator integer) RETURNS SETOF double precision[] AS $BODY$

from scipy.stats import beta import numpy as np from scipy.stats import beta import numpy as np

$BODY$ LANGUAGE plpythonu VOLATILE COST 100 ROWS 1000; ALTER FUNCTION hdi_bars(integer, integer) OWNER TO postgres;

ERROR: ERROR: ImportError: No module named scipy.stats CONTEXT: Traceback (most recent call last): PL/Python function "hdi_bars", line 5, in from scipy.stats import beta PL/Python function "hdi_bars"

********** Error **********

ERROR: ImportError: No module named scipy.stats SQL state: XX000 Context: Traceback (most recent call last): PL/Python function "hdi_bars", line 5, in from scipy.stats import beta PL/Python function "hdi_bars"

Rocky Yost
  • 150
  • 1
  • 1
  • 10
  • please add a short example of the code you are using and the full error traceback. – cel Jul 31 '15 at 21:48
  • Sorry about that. I've updated my post to include some of the code and the error I get back from PostgreSQL. – Rocky Yost Jul 31 '15 at 22:06
  • Are you sure you're running anaconda and not the system python when you do this? (From your script you can do `import sys; print(sys.executable)` to verify.) – Patrick Maupin Aug 01 '15 at 04:53

1 Answers1

3

Based on the Postgres installation/configuration docs, there is an environment variable PYTHON which can be set to the full path of the executable for Python that you want. Otherwise, the default --with-python behavior will look for the system Python, most likely at /usr/bin/python or similar standard location for other operating systems.

This question and answer seems to confirm that to alter it, you need to rebuild Postgres from source.

Community
  • 1
  • 1
ely
  • 74,674
  • 34
  • 147
  • 228