Psycopg2 installation for OS X and Django - python

I would like to use the PostGreSQL database with Django.
I first installed the driver psycopg2 with pip and virtualenv:
$ PATH=$PATH:/Library/PostgreSQL/9.3/bin/
$ pip install psycopg2
[...]
Successfully installed psycopg2
Cleaning up...
$
I have done the following configuration in Django:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_db',
'USER': 'django',
'PASSWORD': 'xx',
'HOST': 'localhost',
'PORT': '5432',
}
}
But when I try to create the schema with syncdb I have the following error:
$ python manage.py syncdb
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen([...]/Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: [...]Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
Do you know why the libssl is not loaded and how can I fix this issue?
Thank you

Related

why django not found module psycopg2 in django2.2 and python 3.8

I install django 2.2.10 and python 3.8 and psycopg2 2.8.4 but when i try migration with command (python manage.py migrate) confront this error:
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
psycopg2 in 32-bit. i try any solution that available in stackoverflow but this error don't dissolve
databases in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'seyyedh',
'PASSWORD' : '123456',
'HOST':'localhost',
'PORT' : '5432',
}
}
Edit:
Sorry, I didn't read your config.
If you are using Postgresql, your Engine-Setting should be 'django.db.backends.postgresql', not 'django.db.backends.postgresql_psycopg2':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'seyyedh',
'PASSWORD' : '123456',
'HOST':'localhost',
'PORT' : '5432',
}
}
as seen here. You probably shouldn't use the initial postgres DB (as referenced in "NAME"), but create a new database for your django project.
Initial answer:
Are you by chance using another python environment than the one configured for your project?
E.g., if you created a virtual environment for you project and have that configured for running the application etc. in your IDE, but for the migration call you are using the python system environment.
If you open the interactive shell for the python environment you are using for migration, and type:
help('modules')
psycopg2 has to be listed!
pip install psycopg2-binary
(or)
pip install psycopg2 for <2.8 psycopg2 versions
(or)
sudo apt-get install python-psycopg2
I understand that psycopg2 installed on another virtual env while main virtual env running
so I unistalled that virtual env and error solved

Migrating django database from sqlite to postgres error with psycopg2

I am trying to switch my django database from sqlite to postgres on my local machine. I am getting the following error when I try to run python manage.py migrate
File "/Users/omarjandali/anaconda3/envs/splittapp/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
Now I did make changes to the settings.py file in order to switch it from the sqlite3 database to the postgres database. My code looks like this.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'splitt',
'USER': 'splittadmin',
'PASSWORD': '*****',
'HOST': 'localhost',
'PORT': '5432',
}
}
This is is what the databse looks like insode of the postgres shell
splitt | splittadmin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
I was also looking up how to grand all rpivileges of a database to a superuser and I was getting mixed results.
Try to install psycopg2:
pip install psycopg2
Have you installed psycopg2 in your virtual environment?
#in a terminal
pip install psycopg2

Django mysqlclient not installed

I was working with sqlite database in local development .
After uploading project to server ubuntu , i installed mysqlclient , but when i try to run makemigrations command this error occurred :
ImportError: No module named 'django.db.backends.mysql'
Try using 'django.db.backends.XXX', where XXX is one of:
'oracle', 'postgresql', 'sqlite3'
When I try to install mysqlclient again , this message will shown :
Requirement already satisfied: mysqlclient in
/home/user/Env/project/lib/python3.5/site-packages (1.3.13)
I also checked project env folder and mysql lib exists in env/python3.5/site-packages !
settings database :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'pass',
'HOST': 'localhost',
'PORT': '',
}
}
install pymysql in your python package manager, and add write in your settings.py
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()

Error loading MySQLdb

I'm facing problem while connecting mysql database in django. I'm getting error as
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL load failed: %1 is not a valid Win32 application.
I have set database setting as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
I don't know where I'm making mistake.
Probably you are using 64bit python/mysql but pip had installed the 32bit mysql-python.
Download the 64bit mysql-python from the link [The link only has support for python 2.7]:
http://www.codegood.com/archives/129
and run the following:
$ pip install path_to_64bit-mysql-python.zip

Django based on PostGreSql error while executing python manage.py runserver- "raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)"

I am creating a Django project based on PostGreSql on Windows OS.
I could successfully download Postgresql (32bits) and psycopg2. I work on a 32 bit Python2.7.9 , and my Postgresql - 9.3.7 32-bits.
import psycopg2 throws NO error.
I could find a psycopg2 folder in Python27\Lib\site-packages
My settings.py contains the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testdb' ,
'USER': 'postgres',
'PASSWORD': 'paggu',
'HOST': 'localhost',
'PORT': '5432',
}
}
But I still get the below error when I try to execute the command- python manage.py runserver or python manage.py syncdb
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: DLL
load failed: The specified module could not be found.
I am not sure if I missed on anything.
I looked up on the other Stack Overflow posts regarding this problem but didn't seem to find any solution.
You may need to actually install psycopg2. To find out run the following in a Windows command prompt:
C:\path\to\project\> python
Then:
>>> help("modules")
If psycopg2 is not in the list, do the following:
Download: psycopg2-2.6.2.win32-py2.7-pg9.5.3-release.exe from HERE, then run the following in a Windows command prompt:
C:\path\to\project> easy_install /path/to/psycopg2-2.6.2.win32-py2.7-pg9.5.3-release.exe

Categories

Resources