سؤال

I am trying to install some python requirements from a local package directory containing wheel archives. I am installing the requirements inside a Docker container.

The steps I'm following are:

$ pip install wheel
# wheel runs, outputs .whl files to wheelhouse directory
$ pip wheel --wheel-dir wheelhouse -r requirements.txt

Then, inside my Dockerfile:

ADD requirements.txt /tmp/requirements.txt
ADD wheelhouse /tmp/wheelhouse
# install requirements. Leave file in /tmp for now - may be useful.
RUN pip install --use-wheel --no-index --find-link /tmp/wheelhouse/ -r /tmp/requirements.txt

This works - and all the requirements are installed correctly:

# 'app' is the name of my built docker image
$ docker run app pip list
...
psycopg2 (2.5.1)
...

However, if I actually try running something inside the container that uses psycopg2, then I get the following:

Error loading psycopg2 module: /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: PyUnicodeUCS4_AsUTF8String

I presume that this is something to do with the way in which the wheels were built - I ran pip wheel on the container host machine (Ubuntu 12.04).

How can I fix this - using wheels significantly reduces the time taken to build the container image, so I don't want to revert to installing packages if I can help it?

هل كانت مفيدة؟

المحلول

I don't know what a wheel or a docker is, but your error comes from a mismatch between the Python used to build the module and the one that is trying to run it.

نصائح أخرى

In my experience, psycopg2 can be rather finicky when installing/building from source, so am not surprised that it doesn't package into a wheel. However, could you simply wheel everything apart from psycopg2? Still would save you a heap of time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top