bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

Can't install django-tenant-schemas to virtualenv in MacOS - psycopg error #598

Open calinbule opened 5 years ago

calinbule commented 5 years ago

Hello, Working on an older project I managed to install it, it also works in the base environment. However, I recently started a new, project, created a new virtual environment with virtualenv, and tried installing django-tenant-schemas but it won't work. I keep getting the errors listed below:

(venv) (base) Calins-iMac:redcm calinbule$ pip install django-tenant-schemas
Collecting django-tenant-schemas
Collecting psycopg2 (from django-tenant-schemas)
  Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

    Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <http://initd.org/psycopg/docs/install.html>).

    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/b7/7mf034nx2mlg8614rpgsjfjc0000gn/T/pip-install-_l5j5ri2/psycopg2/

I am using the latest version of Django (2.2.1) with Python 3.7.2. I even installed psycopg2-binary manually but to no avail. Also, Postgres is up and running as I also use it for other projects.

What I've also tried though, is to install psycopg2 (without the -binary suffix) and I get the same error. I remember that not so long ago when installing it for other projects, I saw some messages that this version will no longer be maintained, and it was recommended that I install the binary version. This leads me to think that the problem is with the db driver rather than with the tenant schemas but, I can't, however, find a solution to this problem as I can't control which version of psycopg the tenant schemas installs.

Any solutons or workarounds? Thank you

rj76 commented 5 years ago

This is not project related. I asume you read https://stackoverflow.com/questions/21079820/how-to-find-pg-config-path

rishikesh67 commented 5 years ago

@rj76, I also faced the same issue. To fix this, install 2.7.3.2 version of psycopg2 » pip install psycopg2==2.7.3.2. It will work. For better guide, check my try-django-tenant-schemas repo at https://hygull.github.io/try-django-tenant-schemas/, here I have documented the steps with a little working example.

Anyways, this package is awesome and the issue whould not be related to this.

rishikesh67 commented 5 years ago

Hello, Working on an older project I managed to install it, it also works in the base environment. However, I recently started a new, project, created a new virtual environment with virtualenv, and tried installing django-tenant-schemas but it won't work. I keep getting the errors listed below:

(venv) (base) Calins-iMac:redcm calinbule$ pip install django-tenant-schemas
Collecting django-tenant-schemas
Collecting psycopg2 (from django-tenant-schemas)
  Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

    Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <http://initd.org/psycopg/docs/install.html>).

    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/b7/7mf034nx2mlg8614rpgsjfjc0000gn/T/pip-install-_l5j5ri2/psycopg2/

I am using the latest version of Django (2.2.1) with Python 3.7.2. I even installed psycopg2-binary manually but to no avail. Also, Postgres is up and running as I also use it for other projects.

What I've also tried though, is to install psycopg2 (without the -binary suffix) and I get the same error. I remember that not so long ago when installing it for other projects, I saw some messages that this version will no longer be maintained, and it was recommended that I install the binary version. This leads me to think that the problem is with the db driver rather than with the tenant schemas but, I can't, however, find a solution to this problem as I can't control which version of psycopg the tenant schemas installs.

Any solutons or workarounds? Thank you

I also faced the same issue. To fix this, install 2.7.3.2 version of psycopg2 » pip install psycopg2==2.7.3.2. It will work. For better guide, check my try-django-tenant-schemas repo at https://hygull.github.io/try-django-tenant-schemas/, here I have documented the steps with a little working example.

Anyways, this package is awesome and the issue should not be related to this.

calinbule commented 5 years ago

Thank you @rishikesh67 for your answer. When I try to install psycopg2-binary it all goes well. The problem is though when installing django-tenant-schemas that has psycopg2 as a dependency (not the binary) and the installation fails. I am still encountering the same problem.

hygull commented 5 years ago

Hi @calinbule,

Questions »

  1. Dependency, you mean using pip?

  2. Did you try pip install psycopg2==2.7.3.2 to install psycopg2 dependency?

Better is to do like this »

Have a look at https://github.com/frictionlessdata/goodtables.io/commit/1351ac49722a1013e41fb1f9ca1a898ad293b6c4 (for clarification).

If you will look at https://github.com/bernardopires/django-tenant-schemas/blob/master/setup.py, you will find:

    install_requires=[
        'Django >= 1.8.0',
        'psycopg2',
    ]

which shows whenever you will install django-tenant-schemas, it will need django>=1.8.0 and latest version of psycopy2 (as no version is specified), we also don't know, what's the problem etc. (it is little time taking interesting task to tackle this).

Make sure you are inside virtual environment with nothing installed (fresh)

  1. pip install psycopg2==2.7.3.2

  2. pip install django-tenant-schemas

That's it.

calinbule commented 5 years ago

Hi @hygull,

Yes, I installed everything using pip, and yes, I tried installing 2.7.3.2 with the same results. I downloaded the package and manually modified the requirements to install a different version of psycopg but I consider it's not a sustainable method. Anyway, I eventually uninstalled the Postgres distribution I had on my system and replaced it with Postgres.app (as the post of @rj76 suggested), added it to the path and, for now at least, it seems to be working. Thank you guys for your help and for your patience.

hygull commented 5 years ago

✅ @calinbule, you are welcome.