Django/Python Beginner: Error When Executing Python Manage.Py Syncdb - Psycopg2 Not Found

Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found

There seems to be a problem with your psycopg2 installation – Python does not find it. This is a Python installation problem, not a Django issue.

You can try to load it manually using the Python interpreter and see if it works:

$ python
>>> import psycopg2

If you get an ImportError exception, your installation is erroneous. To get a list of all directories Python looks for modules, use sys.path:

$ python
>>> import sys
>>> print sys.path

You can also add custom directories to Python's module search path by modifying the sys.path variable. Do this somewhere before the respective import statement(s):

import sys
sys.path.append("my-path")

# ...
import psycopg2

Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found

There seems to be a problem with your psycopg2 installation – Python does not find it. This is a Python installation problem, not a Django issue.

You can try to load it manually using the Python interpreter and see if it works:

$ python
>>> import psycopg2

If you get an ImportError exception, your installation is erroneous. To get a list of all directories Python looks for modules, use sys.path:

$ python
>>> import sys
>>> print sys.path

You can also add custom directories to Python's module search path by modifying the sys.path variable. Do this somewhere before the respective import statement(s):

import sys
sys.path.append("my-path")

# ...
import psycopg2

Postgres with Django - Improperly configured. Error : ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

psycopg2 is not installed in your env.

Make sure you use correct virtualenv (if use), and install psycopg2.

tye pip install psycopg2. (if using pip3, use pip3 install psycopg2).

ps. If you're in ubuntu, install other dependencies

sudo apt-get install build-dep python-psycopg2

python manage.py syncdb fails with ImproperlyConfigured: No module named 'psycopg2'

As suggested in this answer, I attempted to import both psycopg2 and then postgresql_psycopg2 in IPython. Both returned an ImportError.

I saw the PYTHONPATH was empty, so I set it to the above directory

(django_test_venv)jeffy@originaldjangster:~/django_files/django_test$ echo $PYTHONPATH

(django_test_venv)jeffy@originaldjangster:~/django_files/django_test$ export PYTHONPATH=/home/jeffy/django_files/django_test_venv/lib/python3.4/site-packages

But again, both packages resulted in an ImportError in IPython. As in this answer (same question), I ran

sudo apt-get build-dep python-psycopg2

(Trying syncdb here failed the same way.)

and then (adjusted as required, which is mentioned in the question-post)

sudo /home/jeffy/django_files/django_test_venv/bin/pip install psycopg2

And now

python manage.py syncdb

works.

cannot migrate from Django sqlite3 to postgres, getting psycopg2.errors.UndefinedTable: relation doest not exist error

try adding public.

con = psycopg2.connect(
host = 'localhost',
user = 'postgres',
password = '2356216',
database = 'excursion'
)
cursor = con.cursor()
sql = ''
if lang == 'ru':
sql = f"""SELECT ID, Name_ru, Description_ru, Photo, Point_width, Point_longitude, Link
FROM memorable
JOIN communication ON public.communication.memorableid = public.memorable.id
WHERE communication.RouteID = {ExcID}"""
if lang == 'en':
sql = f"""SELECT ID, Name, Description, Photo, Point_width, Point_longitude, Link
FROM memorable
JOIN communication ON communication.memorableid = memorable.id
WHERE communication.RouteID = {ExcID}"""
cursor.execute(sql)
result = cursor.fetchall()
return result

Django runserver error (psycopg2)

I check my local installation of psycopg2

apt-cache show python-psycopg2

Package: python-psycopg2

Priority: optional

Section: python

Installed-Size: 635

...

Source: psycopg2

Version: 2.4.5-1

Depends: python2.7, python (>= 2.7.1-0ubuntu2), python (<< 2.8), libc6 (>= 2.14), libpq5 (>= 8.3~)

So, python-psycopg2 installs you the version which is not compatible with python 3.x But also there is a a package named python3-psycopg2 When I check it, it looks like it is also Version: 2.4.5-1 but descriptive text tells it is compatible with python 3.2

apt-cache show python3-psycopg2

Package: python3-psycopg2

Priority: optional

Version: 2.4.5-1

Provides: python3.2-psycopg2

Depends: python3 (>= 3.2), python3 (<< 3.3), libc6 (>= 2.14), libpq5 (>= 8.3~)

Also, package sizes are different. Probably python3-psycopg2 is what you need, it was only mis-versioned on the documents.

Running python manage.py shell i get Error: DLL load failed: The specified module could not be found.

Trying to compile psycopg2 from the source on Windows is probably going to be very tricky. I recommend the solution I use which is to install the pre-compiled psycopg2 Windows packages graciously provided by the Stickpeople Project from here: http://www.stickpeople.com/projects/python/win-psycopg/.



Related Topics



Leave a reply



Submit