Repository: LineaLabs/lineapy (language: python)

Issue:
Installing psycopg2 from requirements file
**python version**: Python 3.10.6

**lineapy version**: 0.2.1


**Your code**:
```
pip install -r requirements.txt
```

**Issue**:
psycopg2 library does not install with the requirements file.
```
Collecting psycopg2==2.9.3
  Using cached psycopg2-2.9.3.tar.gz (380 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
          /lineapy/env/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file 
parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      running egg_info
      creating /tmp/pip-pip-egg-info-200j4mcn/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-200j4mcn/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-200j4mcn/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-200j4mcn/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-200j4mcn/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
      <https://www.psycopg.org/docs/install.html>).
      
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.
```

I found the [solution](https://stackoverflow.com/a/67586729/18921305) to the problem:
```
sudo apt install python3-dev libpq-dev
```
And again, installing requirements goes without problems.



Discussion / hints:
Hi @lazargugleta, thanks for this detailed bug report! Our team will investigate the issue and get back to you soon!
Interesting, I've actually run into this problem in the past before, but I decided to use `psycopg2-binary` instead. In fact, you can see this in the Dockerfiles for self-hosting example


https://github.com/LineaLabs/lineapy/blob/6a21605aca99d273c0a87b21ba1e64791552dc55/examples/self-hosting-lineapy/lineapy-notebook/Dockerfile#L25 

I wonder if its better to use `psycopg2-binary` since its a "[stand-alone package, not requiring a compiler or external libraries](https://pypi.org/project/psycopg2-binary/)" which should make installing easier. Drawback is they say "The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources." 

I think since Lineapy is mostly used in development right now, this is fine and we should switch over?

@yoonspark @lazargugleta thoughts? 
That occurred to me as well while trying to fix the issue.
It would make sense since, as you said, Linea is in the development stage.

Fix patch:
diff --git a/docs/source/guide/manage_artifacts/storage_location/postgres.rst b/docs/source/guide/manage_artifacts/storage_location/postgres.rst
index 609c0322a..fcc2c23f3 100644
--- a/docs/source/guide/manage_artifacts/storage_location/postgres.rst
+++ b/docs/source/guide/manage_artifacts/storage_location/postgres.rst
@@ -55,7 +55,7 @@ is a Python package called ``psycopg2``, which can be installed as follows:
 
 .. code:: bash
 
-    $ pip install psycopg2
+    $ pip install psycopg2-binary
 
 Connect LineaPy with PostgreSQL
 -------------------------------
diff --git a/requirements.txt b/requirements.txt
index 62d65eac0..b6f40120d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -24,7 +24,7 @@ pdbpp==0.10.3
 pg==0.1
 Pillow==9.1.1
 pre-commit==2.18.1
-psycopg2==2.9.3
+psycopg2-binary==2.9.3
 pydantic==1.9.0
 pytest==6.2.5
 pytest-alembic==0.8.2
diff --git a/setup.py b/setup.py
index 8fbf9309b..838d599da 100644
--- a/setup.py
+++ b/setup.py
@@ -116,7 +116,7 @@ def version(path):
 ]
 
 postgres_libs = [
-    "psycopg2",
+    "psycopg2-binary",
 ]
 
 s3_libs = ["boto3", "s3fs", "botocore"]


Test patch:
diff --git a/tests/tools/requirements_txt_gen.py b/tests/tools/requirements_txt_gen.py
index fa8051a7d..bf47e576d 100644
--- a/tests/tools/requirements_txt_gen.py
+++ b/tests/tools/requirements_txt_gen.py
@@ -86,7 +86,7 @@
     # DBs
     ##
     "pg",
-    "psycopg2",
+    "psycopg2-binary",
     "pytest-xdist",
     "sphinx-autobuild",
 ]