djrobstep / migra

Like diff but for PostgreSQL schemas
https://databaseci.com/docs/migra
The Unlicense
2.92k stars 125 forks source link

More Complete Installation Instructions Please #102

Open jetzerb opened 4 years ago

jetzerb commented 4 years ago

Had some trouble installing migra on Ubuntu 19.10 per the official instructions.

TL;DR

On Ubuntu, the following script ensures that all pre-requisites are present, and then installs migra:

apt-get update;
apt-get install --no-install-recommends python3 python3-setuptools python3-wheel python3-pip;
pip3 install migra[pg];

Gory Details:

Initial attempt at installing via pip install migra[pg] failed with the following error:

Collecting sqlalchemy (from sqlbag->migra)
  Downloading https://files.pythonhosted.org/packages/34/5c/0e1d7ad0ca52544bb12f9cb8d5cc454af45821c92160ffedd38db0a317f6/SQLAlchemy-1.3.11.tar.gz (6.0MB)
    100% || 6.0MB 214kB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named setuptools

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-Ysw65o/sqlalchemy/

Searching through the issues list, I found #46 which says to be sure to use the Python3 version of pip. I removed the python-pip package and installed python3-pip, then tried migra again via pip3 install migra[pg] and got the same error as above 😞

I did see that Ubuntu has a package python3-sqlalchemy, so I installed that and tried migra again. This time, I got the same "No module named setuptools" error while the pathlib dependency was being installed:

Collecting pathlib (from sqlbag->migra)
  Downloading https://files.pythonhosted.org/packages/ac/aa/9b065a76b9af472437a0059f77e8f962fe350438b927cb80184c32f075eb/pathlib-1.0.1.tar.gz (49kB)
    100% || 51kB 1.7MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-o8cybz_q/pathlib/

I found that there is a python3-setuptools package, so I installed that, and then tried migra again. But then I got a new error, although it appears that migra was installed:

Building wheels for collected packages: pathlib
  Running setup.py bdist_wheel for pathlib ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-gfnzjiau/pathlib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile
(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-1w1v9500 --python-tag cp37:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for pathlib
  Running setup.py clean for pathlib
Failed to build pathlib
Installing collected packages: schemainspect, pathlib, sqlbag, migra
  Running setup.py install for pathlib ... done
  The script migra is installed in '/home/jetzerb/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed migra-1.0.1554608452 pathlib-1.0.1 schemainspect-0.1.1571629429 sqlbag-0.1.1548994599

And I confirmed it was indeed successfully installed by pointing migra at two databases and getting the correct upgrade script. However, the "bdist_wheel" error bothered me, so I looked further and saw that there is a Ubuntu package python3-wheel. Once that is installed, the migra installation is successful and error-free.

djrobstep commented 4 years ago

Sorry for the slow reply on this. I believe the documention instructions have expanded a bit since you first reported this. Hopefully we can continue to expand this over time.

jgrocha commented 4 years ago

@jetzerb On my 19.10 I just did:

pip3 install migra
jetzerb commented 4 years ago

@jgrocha Then you must have had all the pre-requisites installed already. Here's a demonstration when starting from a base Ubuntu image:

docker run --rm -it ubuntu:19.10
Unable to find image 'ubuntu:19.10' locally
19.10: Pulling from library/ubuntu
3f2411103a12: Pull complete 
4da04088b2c2: Pull complete 
ab1184837b6f: Pull complete 
354c6da61dcc: Pull complete 
Digest: sha256:f332c4057e21ec71cc8b20b05328d476104a069bfa6882877e0920e8140edcf0
Status: Downloaded newer image for ubuntu:19.10

### First attempt:
root@6e9176fc9fd7:/# pip3 install migra
bash: pip3: command not found

### need to install pip3:
root@6e9176fc9fd7:/# apt-get update && apt-get install --no-install-recommends python3-pip
. . . snip . . .

### Second attempt:
root@6e9176fc9fd7:/# pip3 install migra
Collecting migra
  Downloading https://files.pythonhosted.org/packages/2c/e5/24ec37176d85128ebac2fdb7a97748fb65e1f3435ae1cded022d4e94dd35/migra-1.0.1593567183-py2.py3-none-any.whl
Collecting sqlbag (from migra)
  Downloading https://files.pythonhosted.org/packages/ec/ad/ac257da1c9c63c0a2bb44c77b5fe7a146eea7b1c2be2b251cb0c2c1f8e0c/sqlbag-0.1.1579049654-py2.py3-none-any.whl
Collecting schemainspect>=0.1.1593565676 (from migra)
  Downloading https://files.pythonhosted.org/packages/52/8d/2bebbb9f4b12694c79cbe0b8471ffc3208726074cb1639e3617fc07d8c7b/schemainspect-0.1.1593605722-py2.py3-none-any.whl
Collecting six (from migra)
  Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Collecting pathlib (from sqlbag->migra)
  Downloading https://files.pythonhosted.org/packages/ac/aa/9b065a76b9af472437a0059f77e8f962fe350438b927cb80184c32f075eb/pathlib-1.0.1.tar.gz (49kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 51kB 3.8MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-7_0_frbb/pathlib/

I could continue, but as per the original post, certain packages are required in order for the migra installation to succeed.

alexitheodore commented 2 years ago

More recently, this is what it took for things to work for me:

apt-get update;
apt-get install --no-install-recommends python3 python3-setuptools python3-wheel python3-pip;
apt-get install libpq-dev python3-dev
pip3 install migra[pg];