3

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?

user3799968
  • 1,117
  • 2
  • 8
  • 14

4 Answers4

3

Instead of

pip install psycopg2

try

pip install psycopg2-binary

C S
  • 1,363
  • 1
  • 17
  • 26
0

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.

Andreas
  • 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
  • What does `gcc --version`output? – Andreas Sep 22 '16 at 15:30
  • 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
  • Yes. Did it to fix my pg_config problem – user3799968 Sep 22 '16 at 15:45
0

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!

user4212639
  • 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
0

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
Igor Alex
  • 841
  • 2
  • 10
  • 21