安装时加载psycopg2模块时出错

安装时加载psycopg2模块时出错

本文介绍了从“轮”安装时加载psycopg2模块时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从本地包目录中安装一些python要求,其中包含档案。我正在Docker容器中安装要求。

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.

我遵循的步骤是:

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

然后,在我的 Dockerfile / p>

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)
...

但是,如果我实际上尝试运行使用 psycopg2 ,然后我得到以下内容:

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

我认为这与轮子的构建方式有关 - 我在容器上运行 pip wheel 主机(Ubuntu 12.04)。

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?

推荐答案

我不知道轮子或码头工具是什么,但是您的错误来自于用于构建模块的Python与正在尝试运行的模块之间的不匹配。

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.

这篇关于从“轮”安装时加载psycopg2模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:01