106π
I had the error as well; although psycopg2
was installed on my system using apt-get
, my virtualenv couldnβt find it:
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
It was fixed by doing a pip install psycopg2-binary
inside the virtualenv (or pip install psycopg2
for <2.8 psycopg2 versions).
- [Django]-*_set attributes on Django Models
- [Django]-How to submit form without refreshing page using Django, Ajax, jQuery?
- [Django]-How to 'bulk update' with Django?
19π
I had this problem on a virtualenv
in Ubuntu 18.4.
I solved it by installing psycopg2 v2.7.4:
pip install psycopg2==2.7.4
- [Django]-How to drop all tables from the database with manage.py CLI in Django?
- [Django]-How to concatenate strings in django templates?
- [Django]-Django-tables2: How to use accessor to bring in foreign columns?
- [Django]-Django @login_required decorator for a superuser
- [Django]-What's the purpose of Django setting βSECRET_KEYβ?
- [Django]-Django {% if forloop.first %} question
9π
On MacOS, psycopgy2 v2.8.4 and its binary isnβt compatible with python 3.8 yet.
Downgrade to python 3.7. All works.
1-Β On mac (outside venv), Uninstall 3.8 and then install 3.7 using instructions: https://www.youtube.com/watch?v=X2VXCEfIgC0
2- Go to your django project main folder, delete βvenvβ folder and βmanage.pyβ
3- Install new venv using python 3.7. command:Β python3 -m venv ./venv
4- Run venv. Command: source ./venv/bin/activate
5- Install django in this new venv again. Command: pip3 install django
This will create βdjango-adminβ under ./venv/bin/ and the django libraries.
6- Create manage.py like you would do for a new project again. Command: django-admin startproject <project folder> .
(notice the β.β in end)
The command wont run as previous already exists. So before doing so, rename it to _temp and after running the command which creates a new folder, copy _temp contents to the new . Delete _temp.
7-Run: pip3 install psycopg2
and: pip3 install psycopg2-binary
(If you get an error pg_config executable not found error then run under venv, run following command before installing psycopg again:
export PATH=β/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH)
- [Django]-Django β Static file not found
- [Django]-Python (and Django) best import practices
- [Django]-Where to put business logic in django
7π
You try to load psycopg, not psycopg2.
Make sure that ENGINE is set to django.db.backends.postgresql_psycopg2 in the settings.py of your project:
'ENGINE': 'django.db.backends.postgresql_psycopg2'
May be problem is: 32bit version of Python cannot load a 64bit version of psycopg2.
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
- [Django]-Django gunicorn sock file not created by wsgi
- [Django]-Modulus % in Django template
6π
I was also receiving similar error, it simply means that it is unable to find the βpsycopg2β package/module.
I resolved it simply by installing it in my environment using the command:
pip install psycopg2
- [Django]-Reload django object from database
- [Django]-CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
- [Django]-Django vs. Model View Controller
4π
I hope this command will solve your problem (tested on ubuntu)
pip install psycopg2-binary
- [Django]-Django filter the model on ManyToMany count?
- [Django]-What's the difference between `from django.conf import settings` and `import settings` in a Django project
- [Django]-Django Rest Framework Conditional Field on Serializer
3π
I had this problem inside a python virtual environment (virtualenv), copying the library into the site-package of the environment from the system site packages solved the problem.
- [Django]-Django β SQL bulk get_or_create possible?
- [Django]-Django.db.utils.ProgrammingError: relation already exists
- [Django]-Django MEDIA_URL and MEDIA_ROOT
3π
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: β/usr/local/lib/python3.7/dist-packages/psycopg2β
Consider using the --user
option or check the permissions.
if the above error shows then, please try installing with:
pip install psycopg2-binary βuser
Then it finally works. There is no need to edit on DATABASE ENGINE.
- [Django]-Django celery task: Newly created model DoesNotExist
- [Django]-Django β filtering on foreign key properties
- [Django]-What does "'tests' module incorrectly imported" mean?
- [Django]-AttributeError: 'module' object has no attribute 'tests'
- [Django]-Redirect to Next after login in Django
- [Django]-How to run celery as a daemon in production?
2π
Run the below command in Command Line Prompt
pip install psycopg2
This will install psycopg2 and resolve the issue.
- [Django]-Django proxy model and ForeignKey
- [Django]-How to query Case-insensitive data in Django ORM?
- [Django]-Django or Django Rest Framework
1π
I have been suffering from these problems recently. I run the below code in cmd.
python -m pip install "psycopg[binary]"
The problem is solved.
- [Django]-Django Rest Framework remove csrf
- [Django]-Django β How to rename a model field using South?
- [Django]-Using Python's os.path, how do I go up one directory?
1π
I know my reply is coming late but it might still help some people. I ran into this problem a few days ago and tried all the solutions provided here but none worked for me except this:
pip install --upgrade pip # to upgrade pip
pip install "psycopg[binary,pool]" # to install package and dependencies
I got the solution from the documentation check it here.
- [Django]-Error trying to install Postgres for python (psycopg2)
- [Django]-Django in / not in query
- [Django]-How to annotate Count with a condition in a Django queryset
0π
First:
pip uninstall psycopg2
Then, load the direct file from http://www.stickpeople.com/projects/python/win-psycopg/
file name : = psycopg2-2.6.2.win-amd64-py2.7-pg9.5.3-release.exe
As per your requirement, and then copy this downloaded file to env folder and do this:
easy_install psycopg2-2.6.2.win-amd64-py2.7-pg9.5.3-release.exe(your file name)
This will copy required files.
- [Django]-How can I use redis with Django?
- [Django]-Render HTML to PDF in Django site
- [Django]-Django: Open uploaded file while still in memory; In the Form Clean method?
0π
It can happen if you donβt have psycopg2
installed already.
I had this problem with the virtualenv, I simply installed psycopg2
and it is working fine. No need to edit the db configurations.
pip install psycopg2
- [Django]-Django-taggit β how do I display the tags related to each record
- [Django]-How to import csv data into django models
- [Django]-Django Rest Framework: Dynamically return subset of fields
0π
This Problem can be of any reason β
-
You have downloaded the wrong version of pyscog2 that doesnβt support the current version of the Django.
-
You might have placed the pyscopg2 in the wrong directory.
-
You might have downloaded the pyscopg2 without the virtual environment and then activated post-install so it may be showing error.
-
Bad configuration of the virtual environment in manage.py leads to the error.
-
See the proper configuration it may be taking pyscopg2 from the root folder rather than the virtual environment.
- [Django]-Elegant setup of Python logging in Django
- [Django]-Django CSRF Cookie Not Set
- [Django]-Creating email templates with Django
0π
sudo apt-get install python3-psycopg2
Worked on Ubuntu 20.04, python 3.10.4, Django 4.1.
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-Django TextField and CharField is stripping spaces and blank lines
- [Django]-You are trying to add a non-nullable field 'new_field' to userprofile without a default