Import the 'psycopg2' module - Error

Hi,

When I try to connect to to Postgresql from Anvil Server model I get the following error:

You tried to import the ‘psycopg2’ module.
This module is available in the full Python 2.7 and Python 3.6 runtimes. Change the Python version in your server modules if you want to use the ‘psycopg2’ module.

I have Python 3.7.3 installed on my computer and I use Postgresql created by PgAdmin 2 in a Desktop Python application.

I would be very grateful for any advice.

Thanks, Talib

In the server module, towards the top right corner of the code area there is a drop down where you can select the Python version :
image
By default, this is “Restricted Python 2”. You need to change it to one of the others to be able to import modules.

Hi @talib.damij,

Also, if you are using your locally installed Python interpreter, on your computer, then you will need to use the Uplink rather than Server Modules.

1 Like

Many thanks, David and Meredydd.

I had a similar issue. However, when I tried changing the Python version in my server module I got a warning message that says Python 3 runtime is not available in my account. I just upgraded to the individual plan, which is meant to allow ‘Full Python Runtime’.

Annotation 2020-07-05 221852

Any ideas?

I tried refreshing my browser, and got a message clarifying that it’ll take 24 hours to activate the Full Python in my account. So, problem solved—I guess!

1 Like