I have postgresql installed (with postgresql app). When I try "pip install psycopg2", i get "unable to execute gcc-4.2: No such file or directory. How to fix?
-
gcc-4.2 is not installed. Does this solve your issue? http://stackoverflow.com/a/8424885/4291583 – Tom Yates Sep 22 '16 at 15:25
-
if you mean : "sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2"; then nope – user3799968 Sep 22 '16 at 15:32
4 Answers
You will need XCode to compile with gcc on macOS. Install it with this command in the terminal:
xcode-select --install
Or you cold install it from the app store.

- 1,091
- 1
- 11
- 16
-
It is already installed, forgot to mention that im trying to install within a virtual environment – user3799968 Sep 22 '16 at 15:27
-
-
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 8.0.0 (clang-800.0.38) Target: x86_64-apple-darwin15.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin – user3799968 Sep 22 '16 at 15:32
-
Is the path to Postgres.app binaries available in the virtual environment? Set it with: `export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin` – Andreas Sep 22 '16 at 15:37
-
You should use virtualenv and Python Setup Tools/PIP to install all you packages for django. This makes your job of package installs/upgrades very easy.
pip install virtualenv
This will install the virtualenv. Now create and activate a virtual environment using this virtualenv like this:
virtualenv <any_name_you_want_for_this_virtual_env>
e.g.
virtualenv api-venv
This will create a directory: api-venv in the current directory you are in. Now activate this environment and then install all your packages using 'pip' command. This way, pip will install all packages inside this api-venv environment only.
source api-venv/bin/activate
Now the api-venv is activated. Let's install 'psycopg2'
pip install psycopg2
I would recommend to install django inside this venv so everything is in the venv.
pip install django
You can create as many such virtual environments as you like with different configuration. Done!

- 489
- 6
- 6
-
decent advice but you aren't really addressing OP's issue with needing to compile `psychopg2`. The `pip install` isn't going to help there. – C S Jul 31 '18 at 03:30
You can try this way. First, you should install PostgreSQL through brew.
brew install postgresql
Then you should add pg_config to PATH. You can find pg_config with.
which pg_config
Finally, install psycopg2 with pip.
pip install psycopg2

- 841
- 2
- 10
- 21