从源代码构建python,_sqlite3已构建但未导入

问题描述 投票:0回答:1

我有一个 Rocky Linux 9.0 服务器,我们在上面使用 modules。我正在尝试从源代码编译不同版本的python,并将它们打包到用户可以根据需要加载的模块中。但不幸的是,我一直在努力从源代码构建它们。

首先,如果有人对如何构建包含特定 python 版本(即不编译)有一个好的替代方案,请随时告诉我,我也很感激对此的一些提示,但这不是这篇文章的问题。

我有以下脚本要下载和构建

moduls

及其依赖项

python
sqlite

当我运行脚本并在 
#!/bin/bash # build a python module # based on: https://stackoverflow.com/questions/43993890/modulenotfounderror-no-module-named-sqlite3 # Save current working directory CURR_DIR="$(pwd)" # Set working directory to the location of this file cd "$(dirname "${BASH_SOURCE[0]}")" # config PYTHON_VERSION=3.11.7 INSTALL_BASE_PATH="/modules/shared/apps/python/${PYTHON_VERSION}" SQLITE_VERSION=3450000 # clear the install directory rm -rf ${INSTALL_BASE_PATH} # download python mkdir build cd build [ -f "Python-${PYTHON_VERSION}.tgz" ] || wget --no-check-certificate "https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz" tar -zxf "Python-${PYTHON_VERSION}.tgz" # download sqlite # https://www.sqlite.org/2024/sqlite-autoconf-3450000.tar.gz SQLITE_URL="https://www.sqlite.org/2024/sqlite-autoconf-${SQLITE_VERSION}.tar.gz" echo "Downloading SQLite from ${SQLITE_URL}" [ -f "sqlite-autoconf-${SQLITE_VERSION}.tar.gz" ] || wget --no-check-certificate "${SQLITE_URL}" tar -zxf "sqlite-autoconf-${SQLITE_VERSION}.tar.gz" # install sqlite cd sqlite-autoconf-${SQLITE_VERSION} ./configure --prefix=${INSTALL_BASE_PATH} make make install # install python cd "../Python-${PYTHON_VERSION}" export PKG_CONFIG_PATH="${INSTALL_BASE_PATH}/lib/pkgconfig" ./configure --prefix=${INSTALL_BASE_PATH} --enable-loadable-sqlite-extensions LDFLAGS="-L${INSTALL_BASE_PATH}/lib" CPPFLAGS="-I${INSTALL_BASE_PATH}/include" CFLAGS="-I${INSTALL_BASE_PATH}/include" make -j 8 read -p "Compiled python, check for errors and press key to continue..." make install # create a symlink for python (cd "${INSTALL_BASE_PATH}/bin"; ln -s python3 python) # set working directory back to original cd $CURR_DIR read -p "Done, press key to finish..."

之后检查错误时,我看到以下内容:

make -j 8

我试图保持底层操作系统不变,因此安装通常的预编译
*** WARNING: renaming "_sqlite3" since importing it failed: /path/to/python/build/Python-3.11.7/build/lib.linux-x86_64-3.11/_sqlite3.cpython-311-x86_64-linux-gnu.so: undefined symbol: sqlite3_deserialize The necessary bits to build these optional modules were not found: _gdbm _tkinter nis readline To find the necessary bits, look in setup.py in detect_modules() for the module's name. Following modules built successfully but were removed because they could not be imported: _sqlite3

并不是一个真正的选择。

这里有一个类似的问题,但没有太多对我有帮助的答案。有人知道问题可能是什么吗?

您需要定义LD_LIBRARY_PATH:

python linux sqlite
1个回答
0
投票

构建完 Python 后,您需要放入 ~/.bashrc :

# install python
cd "../Python-${PYTHON_VERSION}"
export LD_LIBRARY_PATH=${INSTALL_BASE_PATH}/lib
export PKG_CONFIG_PATH="${INSTALL_BASE_PATH}/lib/pkgconfig"

© www.soinside.com 2019 - 2024. All rights reserved.