186π
The python-dev
package is required for compilation of Python extensions written in C or C++, like psycopg2
. If youβre running a Debian-based distribution (e.g. Ubuntu), you can install python-dev
by running
sudo apt install python-dev
or
sudo apt install python3-dev
depending on your python version (for example, sudo apt install python3.8-dev
).
After that, proceed to install psycopg2
in your virtualenv
environment as usual.
60π
For Ubuntu 14.04
, from Docker image python:3.4.3-slim
this combination worked for me:
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y python3.4-dev
sudo apt-get install -y libpq-dev
pip3 install psycopg2
Note build-essential
package. It was crucial in my case.
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-How can one use enums as a choice field in a Django model?
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
15π
I tried all the solution but only works be
pip install psycopg2-binary
after installing lib you can use import psycopg2
in python file and then further db connection config
- [Django]-What is the easiest way to clear a database from the CLI with manage.py in Django?
- [Django]-How to save pillow image object to Django ImageField?
- [Django]-How to filter objects for count annotation in Django?
13π
In my case (ubuntu 12.04 with python 2.7 and python 3.4 installed)
sudo apt-get install python3-dev
was not enough. What did the trick was
sudo apt-get install python3.4-dev
- [Django]-Django β Render the <label> of a single form field
- [Django]-When to use Serializer's create() and ModelViewset's perform_create()
- [Django]-How to find pg_config path
6π
On Amazon Linux within a python3 venv I had to do the following:
sudo yum install python3-devel postgresql-devel
pip install psycopg2
- [Django]-Django query get last n records
- [Django]-Django: how save bytes object to models.FileField?
- [Django]-Django url tag multiple parameters
- [Django]-Tailwindcss: fixed/sticky footer on the bottom
- [Django]-.filter() vs .get() for single object? (Django)
- [Django]-How to update an existing Conda environment with a .yml file
4π
For the latest Python 3.7 I had to install python3.7-dev
:
sudo apt-get install -y python3.7-dev
- [Django]-How to get the current URL within a Django template?
- [Django]-With DEBUG=False, how can I log django exceptions to a log file
- [Django]-How to automate createsuperuser on django?
3π
First of all install python-dev
sudo apt-get install python-dev
And to adecuate use try this:
This is to do with the encoding of your terminal not being set to UTF-8. Here is my terminal:
$ echo $LANG
es_UY.UTF-8
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
(qο½₯Οο½₯q)οΎ
>>>
If I unset I got the same error you got:
$ unset LANG
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)
>>>
- [Django]-Naming convention for Django URL, templates, models and views
- [Django]-Django: Reference to an outer query may only be used in a subquery
- [Django]-What's the difference between select_related and prefetch_related in Django ORM?
2π
Iβm using the Ubuntu distribution of Linux and did the following:
Install the latest version of the python3-dev library so C extensions work for python. The first command updates the package list in Ubuntu so the latest version of python3-dev is installed.
sudo apt-get update
sudo apt-get install python3-dev
Then I had to install the the missing development library for PostgreSQL: the "libpq-dev" package.
sudo apt-get install libpq-dev
After that, I was able to finish installing my dependencies.
- [Django]-Django: Filter a Queryset made of unions not working
- [Django]-What is reverse()?
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?
1π
sudo apt-get install -y build-essential after trying everything
with no success this helped me solve my problem.
- [Django]-Is there a naming convention for Django apps
- [Django]-Paginating the results of a Django forms POST request
- [Django]-How to get getting base_url in django template
0π
In my case, I tried to install psysopg2 version 2.7.3.2 in a virtual environment with python3.8.
The above error occurred.
As it turned out, python3.8 requires psycopg2 version 2.8 or higher.
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-Django Model MultipleChoice
- [Django]-Django connection to postgres by docker-compose
-1π
Remove the current virtual environment and create another one. Install the dependencies first then the rest youβve been using. This works
- [Django]-How can I handle Exceptions raised by dango-social-auth?
- [Django]-How do you Serialize the User model in Django Rest Framework
- [Django]-Django values_list vs values