我有一个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 

我试图让底层操作系统保持不变,所以安装通常预编译的sqlite-devel不是一个真正的 Select .

有一个类似的问题here,但没有多少答案对我有帮助.有谁知道这可能是什么问题吗?

推荐答案

您需要定义LD_LIBRARY_PATH:

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

在构建了Python之后,您需要放入~/.bashrc:

export LD_LIBRARY_PATH=/modules/shared/apps/python/3.11.7/lib

Python相关问答推荐

如何在solve()之后获得症状上的等式的值

PyQt5,如何使每个对象的 colored颜色 不同?'

如何从数据库上传数据到html?

如何启动下载并在不击中磁盘的情况下呈现响应?

为什么numpy. vectorize调用vectorized函数的次数比vector中的元素要多?

旋转多边形而不改变内部空间关系

干燥化与列姆化的比较

Pandas:填充行并删除重复项,但保留不同的值

Python类型提示:对于一个可以迭代的变量,我应该使用什么?

如何在Python中将超链接添加到PDF中每个页面的顶部?

如何将一个文件的多列导入到Python中的同一数组中?

在不中断格式的情况下在文件的特定部分插入XML标签

具有不同坐标的tkinter canvs.cocords()和canvs.moveto()

如何删除剪裁圆的对角线的外部部分

多个布尔条件的`jax.lax.cond`等效项

torch 二维张量与三维张量欧氏距离的计算

我应该使用哪一个来判断python中枚举值的唯一性?

Chrome 122-如何允许不安全的内容?(不安全下载被阻止)

盒子图分析

滚动加权平均(或类似)填充失踪大Pandas