user14537917
user14537917

Reputation: 3

Unable to access postgreSQL database using psycopg2 with pythonista app

I am a relatively new to programming and I am working on an application that utilizes an AWS RDS PostgreSQL Database to allow me to create or update information on the applicaiton accross my devices, specifically between my 2016 Windows 10 surfacebook and my iphone 8+.

Using psycopg2, I can connect to my database relatively easily using my surfacebook. However I am now trying to develop the mobile counterpart using the Pythonista app (a python interpreter for Iphones that allows you to create and execute python programs) and have run into a problem with the psycopg2 module.

using the StaSh terminal (a script for Pythonista that allows for pip installations on mobile) I installed psycopg2 using pip install psycopg2 but when I tried to run the program:

import psycopg2

conn = psycopg2.connect(
    host="localhost",
    database="database",
    user="user",
    password="password"
)
c = conn.cursor()

def list_all_accounts():
    with conn:
    c.execute("SELECT * FROM table")
        result = c.fetchall()
    return result

import pprint
pprint.pprint(list_all_accounts())

I got a ModuleNotFoundError full traceback :

  File "/private/var/mobile/Containers/Shared/AppGroup/60906921-DCB6-478D-898E-EDA48296C57C/Pythonista3/Documents/my-apps/Pandle/model.py", line 9, in <module>
    import psycopg2
  File "/private/var/mobile/Containers/Shared/AppGroup/60906921-DCB6-478D-898E-EDA48296C57C/Pythonista3/Documents/site-packages-3/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'

when I checked the installed modules there is indeed no module called _psycopg in the psycopg2 directory.

I also tried using pip install pyscopg2-binary and that didn't work either. I would like to know if anyone knows if I can use pyscopg2 to access remote AWS PostgreSQL Databases using Pythonista or if perhaps Pythonista itself has some sort of limitation I am not aware of in this regard. Thank you for your help.

Upvotes: 0

Views: 593

Answers (1)

Mikael
Mikael

Reputation: 161

Pythonista does not support pip installing binaries and has no compiler for C code.

There is a pure Python alternative pg8000 which at least 1 Pythonista user has reported to work.

Upvotes: 0

Related Questions