New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyscopg2 #1

Closed
cshuman opened this Issue Feb 3, 2016 · 16 comments

Comments

Projects
None yet
7 participants
@cshuman

cshuman commented Feb 3, 2016

Any idea on which dependencies need to be installed in alpine linux to be able to pip install psycopg2?

@frol

This comment has been minimized.

Owner

frol commented Feb 4, 2016

@cshuman I don't recall exact package names and I'm out of good Internet connection, so I can't check them for you now, but you will need python3-dev and libpostgres.

@frol

This comment has been minimized.

Owner

frol commented Feb 5, 2016

@cshuman I have successfully installed psycopg2 after installing (apk add) the following packages: postgresql-dev, gcc, python3-dev, musl-dev.

@lockie

This comment has been minimized.

lockie commented Oct 18, 2016

You could've just install py3-psycopg2 package actually.

@frol

This comment has been minimized.

Owner

frol commented Oct 18, 2016

@lockie It was not available at that moment, and in fact, it is only py-psycopg2 (for Python 2.7) available right now in the stable Alpine 3.4.

@lockie

This comment has been minimized.

lockie commented Oct 18, 2016

@frol Yeah, you're right, its still in the edge now.

@kim0

This comment has been minimized.

kim0 commented Nov 4, 2016

I tried installing it from edge, and while it seems to work, python can't import it!

/ # apk add --no-cache py3-psycopg2
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
OK: 107 MiB in 45 packages
/ # ls /usr/lib/python3.5/site-packages/
README                         easy_install.py                pip-8.1.1.dist-info            psycopg2                       setuptools
__pycache__                    pip                            pkg_resources                  psycopg2-2.6.2-py3.5.egg-info  setuptools-20.10.1.dist-info
/ # python3
Python 3.5.2 (default, Oct 18 2016, 23:58:46)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'psycopg2'
>>>

@lockie .. any idea what's wrong

@frol

This comment has been minimized.

Owner

frol commented Nov 4, 2016

@kim0 It works for me...

$ docker run -it --rm frolvlad/alpine-python3 sh
/ # apk add --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --no-cache py3-psycopg2
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
(1/8) Installing libressl2.4-libcrypto (2.4.3-r1)
(2/8) Installing libgcc (6.2.1-r1)
(3/8) Installing db (5.3.28-r0)
(4/8) Installing libsasl (2.1.26-r8)
(5/8) Installing libressl2.4-libssl (2.4.3-r1)
(6/8) Installing libldap (2.4.44-r3)
(7/8) Installing libpq (9.6.0-r1)
(8/8) Installing py3-psycopg2 (2.6.2-r1)
OK: 78 MiB in 30 packages
/ # python3
Python 3.5.2 (default, Sep 26 2016, 17:11:38)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> psycopg2.__version__
'2.6.2 (dt dec pq3 ext lo64)'
>>> 
@lockie

This comment has been minimized.

lockie commented Nov 4, 2016

@kim0 Your ls output suggests psycopg was not actually installed. That's odd. What docker image are you using?

@kim0

This comment has been minimized.

kim0 commented Nov 4, 2016

@lockie I am testing with python:3.5.2-alpine .. Just tried with the instructions above, also didn't work

@lockie

This comment has been minimized.

lockie commented Nov 4, 2016

@kim0 I think you're mixing python packages from python docker image (which reside in /usr/local/lib) with packages installed by apk, which reside in /usr/lib. Use alpine:edge as your base docker image, that should do the trick.

@kim0

This comment has been minimized.

kim0 commented Nov 4, 2016

Thanks, that makes sense. I thought python folks used alpine packages I guess. Alright

@lockie

This comment has been minimized.

lockie commented Nov 4, 2016

Yeah, they're, like, totally building python from source, which seems strange to me too.
You're welcome :)

@frol

This comment has been minimized.

Owner

frol commented Nov 4, 2016

@kim0 Just in case if you haven't noticed, this repository doesn't have any relation to the official python:alpine images.

@yamila-moreno

This comment has been minimized.

yamila-moreno commented Jan 31, 2018

this thread is still useful \o/ It made my day, thank you! :D

@sawall

This comment has been minimized.

sawall commented Aug 29, 2018

For reference, stackoverflow response provides a fairly clean way to do it from the requirements install without adding the py3-psycopg2 package. It also removes postgresql-dev after the psycopg2 install, which saves some space: https://stackoverflow.com/questions/46711990/error-pg-config-executable-not-found-when-installing-psycopg2-on-alpine-in-dock

RUN apk update && \
 apk add postgresql-libs && \
 apk add --virtual .build-deps gcc musl-dev postgresql-dev && \
 python3 -m pip install -r requirements.txt --no-cache-dir && \
 apk --purge del .build-deps
@kenneho

This comment has been minimized.

kenneho commented Sep 6, 2018

Another approach based on https://asciinema.org/a/172825:

RUN apk --no-cache add build-base
RUN apk --no-cache add postgresql-dev
RUN python3 -m pip install psycopg2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment