131π
I recommend that you try to use Postgres.app. (http://postgresapp.com)
This way you can easily turn Postgres on and off on your Mac.
Once you do, add the path to Postgres to your .profile
file by appending the following:
PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Only after you added Postgres to your path you can try to install psycopg2
either within a virtual environment (using pip) or into your global site packages.
52π
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
- [Django]-Django delete FileField
- [Django]-Django CMS fails to synch db or migrate
- [Django]-Adding to the "constructor" of a django model
37π
Installing homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
And then installing postgresql
brew install postgresql
gave me this lovely bit of output:
checking for pg_config... yes
ahhh yeahhhhh
- [Django]-What is the purpose of adding to INSTALLED_APPS in Django?
- [Django]-Django get objects not referenced by foreign key
- [Django]-How to get getting base_url in django template
28π
Postgres.app was updated recently. Now it stores all the binaries in βVersionsβ folder
PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
Where 9.4 βΒ version of PostgreSQL.
- [Django]-Tying in to Django Admin's Model History
- [Django]-Django Rest Framework β Authentication credentials were not provided
- [Django]-How to change the name of a Django app?
19π
Once you install the current PostgreSQL app on the MacOS X 10.11, this is where the pg_config file is /Library/PostgreSQL/9.5/bin/pg_config
.
Then on the Terminal:
$ export PG_HOME=/Library/PostgreSQL/9.5
$ export PATH=$PATH:$PG_HOME/bin
This will put the path in the .profile of whatever terminal you are using.
In your environment (assuming you are using virtualenv
) you then install psycopg2:
$ pip install psycopg2
You should see if you had downloaded it before:
Collecting psycopg2
Using cached psycopg2-2.6.1.tar.gz
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.6.1
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
- [Django]-(13: Permission denied) while connecting to upstream:[nginx]
- [Django]-CSRF Failed: CSRF token missing or incorrect
8π
To summarize β PostgreSQL installs its files (including its binary or executable files) in different locations, depending on the version number and the installation method.
Some of the possibilities:
/usr/local/bin/
/Library/PostgreSQL/9.2/bin/
/Applications/Postgres93.app/Contents/MacOS/bin/
/Applications/Postgres.app/Contents/Versions/9.3/bin/
No wonder people get confused!
Also, if your $PATH environment variable includes a path to the directory that includes an executable file (to confirm this, use echo $PATH
on the command line) then you can run which pg_config
, which psql
, etc. to find out where the file is located.
- [Django]-How to remove all of the data in a table using Django
- [Django]-Get the latest record with filter in Django
- [Django]-Create custom buttons in admin change_form in Django
7π
This is how to simply get the path of pg_config
$ which pg_config // prints the directory location
/usr/bin/pg_config
- [Django]-Django β iterate number in for loop of a template
- [Django]-Override existing Django Template Tags
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
6π
I had exactly the same error, but I installed postgreSQL through brew and re-run the original command and it worked perfectly :
brew install postgresql
- [Django]-Why won't Django use IPython?
- [Django]-Django check if a related object exists error: RelatedObjectDoesNotExist
- [Django]-How do I deploy Django on AWS?
6π
Have same issue on mac, you probably need to
brew install postgresql
then you can run
pip install psycopg2
The brew will fix PATH issue for you
this solution works for me at least.
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-AssertionError: database connection isn't set to UTC
- [Django]-How can I keep test data after Django tests complete?
3π
You can find the pg_config
directory using its namesake:
$ pg_config --bindir
/usr/lib/postgresql/9.1/bin
$
Tested on Mac and Debian. The only wrinkle is that I canβt see how to find the bindir for different versions of postgres installed on the same machine. Itβs fairly easy to guess though! π
Note: I updated my pg_config to 9.5 on Debian with:
sudo apt-get install postgresql-server-dev-9.5
- [Django]-Django: Why do some model fields clash with each other?
- [Django]-Django form: what is the best way to modify posted data before validating?
- [Django]-Can "list_display" in a Django ModelAdmin display attributes of ForeignKey fields?
2π
For people looking for the pg_config path for postgresql installed via brew on Apple silicon: /opt/homebrew/Cellar/postgresql/<postgres_version>/bin
.
For Intel based Mac system /usr/local/Cellar/postgresql/<postgres_version>/bin
(Need to verify this).
- [Django]-Filtering using viewsets in django rest framework
- [Django]-How to add a cancel button to DeleteView in django
- [Django]-Django β query filter on manytomany is empty
1π
check /Library/PostgreSQL/9.3/bin and you should find pg_config
I.E. /Library/PostgreSQL/<version_num>/
ps: you can do the following if you deem it necessary for your pg needs β
create a .profile in your ~ directory
export PG_HOME=/Library/PostgreSQL/9.3
export PATH=$PATH:$PG_HOME/bin
You can now use psql
or postgres
commands from the terminal, and install psycopg2 or any other dependency without issues, plus you can always just ls $PG_HOME/bin
when you feel like peeking at your pg_dir.
- [Django]-Django 1.3.1 compilemessages. Error: sh: msgfmt: command not found
- [Django]-Invalid http_host header
- [Django]-Django REST Framework: how to substitute null with empty string?
- [Django]-Folder Structure for Python Django-REST-framework and Angularjs
- [Django]-How do I get user IP address in Django?
- [Django]-Django's Double Underscore
1π
Works for me by installing the first the following pip packages: libpq-dev
and postgresql-common
- [Django]-Homepage login form Django
- [Django]-Why doesn't django's model.save() call full_clean()?
- [Django]-Retrieving parameters from a URL
1π
For those using macOS Big Sur and have their default shell as the Z shell, you can add the path to the py_config binary in the .zprofile which is equivalent to the .bash_profile as explained in this link https://support.apple.com/en-us/HT208050
I had similar issues when using PyCharm with a virtual environment within which I was unable to change my shell to bash to get things going. Adding the postgres bin path fixed my issue:
MacBook-Pro ~ % cat .zprofile
# Setting PATH for Postgres
PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
export PATH
Then running this worked without any issues:
pip install psycopg2
- [Django]-Django β Overriding the Model.create() method?
- [Django]-Django count RawQuerySet
- [Django]-Django 2.0 β Not a valid view function or pattern name (Customizing Auth views)
0π
path of pg_config in my case (MacOS)
/Library/PostgreSQL/13/bin
Execute the following in the terminal:
PATH="/Library/PostgreSQL/13/bin:$PATH"
Then
pip install psycopg2
- [Django]-Bypass confirmation prompt for pip uninstall
- [Django]-How do you Serialize the User model in Django Rest Framework
- [Django]-Django Rest Framework: Dynamically return subset of fields