(venv) D:\geodj\geodjango>python manage.py makemigrations
Traceback (most recent call last):
File "D:\geodj\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 25, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
from django.db.backends.postgresql.base import (
File "D:\geodj\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 29, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
(venv) D:\geodj\geodjango>pip install psycopg2
Collecting psycopg2
Using cached psycopg2-2.8.5-cp37-cp37m-win_amd64.whl (1.1 MB)
Installing collected packages: psycopg2
Successfully installed psycopg2-2.8.5
运行出错:ImportError: No module named psycopg2
import psycopg2
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named psycopg2
安装出错:
[root@localhost pyscript]# pip install psycopg2
DEPRECATION: Python 2.7 reached the end of its l
在使用Django连接postgresql数据库的时候,使用python manage.py migrate创建数据库时提示:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
解决办法:
apt install psycopg2如果失败了...
Error loading psycopg2 module: No module named ‘psycopg2’,
此问题的存在是在Django在连接自己的数据库是所报错的
官方文档也有明确的解决办法
在setting.py 中设置连接属性
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydat
在 Mac 下使用 PostgreSQL 首先要安装
http://www.cnblogs.com/shineqiujuan/p/4703304.html (一个比较好的网站有详细的安装过程)
安装结束后,在你的Django 工程的setting.py 文件中配置:
DATABASES = {
'default': {
'ENGINE': 'django.db.