【问题标题】:Python build finished, but the necessary bits to build these modules were not foundPython 构建完成,但未找到构建这些模块的必要位
【发布时间】:2020-07-11 22:26:08
【问题描述】:

python2 的官方支持几个月前结束了,但我需要它来运行我的一个程序,并且它已从 ubuntu 20.04 存储库中删除。所以我想自己编译和安装 python2。但在结束时make all(实际上在 setup.py build) 的各个阶段,它会打印以下错误:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _ssl            
_tkinter           bsddb185           bz2             
dbm                dl                 gdbm            
imageop            readline           sunaudiodev     
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

我不关心readline_tkinter 等模块,但我需要_ssl。无法通过pip 安装它。
我从存储库安装了libssl-dev,但是在重新构建之后出现了以下错误:

Failed to build these modules:
_hashlib           _ssl

感谢任何帮助。
谢谢。

【问题讨论】:

  • 我在 Ubuntu 18.0.4 下尝试从源代码编译 python 2.7.18 时遇到了完全相同的问题。有什么解决办法吗?

标签: linux compiler-errors python-2.x python-module


【解决方案1】:

说实话,我宁愿为Python2 使用 docker 映像,也不愿尝试编译它;对某些人来说可能有点矫枉过正,但对我来说,这是更简单、更干净的方式。

例如,如果您有一个project 文件夹,其中至少包含project.pyrequirements.txt,您可以使用以下Dockerfile(与project 在同一文件夹中):

FROM python:2.7-slim-buster

COPY /project /app
RUN pip install --no-cache-dir -r /app/requirements.txt

WORKDIR /app

CMD [ "python", "project.py" ]

使用docker build -t project . 构建它

使用docker run -it --rm --name project_run project 运行它

根据您的应用程序的复杂程度,您还可以尝试更新它,以便在 Python 3 上运行(也有自动化工具可以帮助您)。

【讨论】:

  • 虽然不是模块构建问题的解决方案,但确实是一个不错的选择。谢谢。
猜你喜欢
  • 1970-01-01
  • 2022-11-01
  • 2017-10-18
  • 1970-01-01
  • 2020-11-19
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多