将 tcl 8.6 与已编译的 python 一起使用

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

要求:

We want to build python v3.6.4 from source and then distribute it as tar so that it can be used in different machine by just untarring it. The built python needs to work with tcl v8.6

问题:

Built python is looking for tcl8.5

构建机器:

CentOS 7

搭建步骤如下:

 - yum -y install openssl-devel wget gcc make tk-devel
 - wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
 - mkdir -p /opt/mayur/python/3.6.4/lib
 - tar -xvf Python-3.6.4.tgz
 - cd Python-3.6.4
 - ./configure --prefix=/opt/mayur/python/3.6.4 --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /opt/mayur/python/3.6.4/lib"
 - make altinstall 
 - tar cvf python3.6.4.tar -C /opt/mayur/python/3.6.4/

接下来,当我在另一台机器上将上面构建的 tar 解压到 /opt/mayur/python/3.6.4 并运行

import tkinter
时,它会抛出以下错误 -

File "/opt/mayur/python/3.6.4/lib/python3.6/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: libtk8.5.so: cannot open shared object file: No such file or directory

通过一些调试,我了解到centos仅支持tk-devel 8.5。所以第一步安装的 tk-devel 版本是 v8.5.13,所以,python 正在寻找 libtk8.5.so。

我看到了这篇文章post并将我的配置更改为

./configure --prefix=/opt/mayur/python/3.6.4 --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /opt/mayur/python/3.6.4/lib" --with-tcltk-includes=-I/opt/mayur/tcl/8.6.6.8606/include --with-tcltk-libs=-L/opt/mayur/tcl/8.6.6.8606/lib

但这也行不通。

有人可以指点一下如何构建 python v3.6.4 并将其链接到 tcl8.6 吗? python 如何决定使用哪个 tcl?

python tkinter tcl python-3.6
1个回答
0
投票

对于可能发现此内容的人,这是在 Centos 7 上编译最新 TCL/TK 8.6 和 Python 3.7 的方法。

  • 安装构建要求
# TCL/TK requirements
yum install gcc libX11-devel
# Python requirements
yum install wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel sqlite-devel
  • 下载并安装TCL

请注意,需要构建 以避免在 python 编译时出现

undefined symbol
错误。

mkdir /opt/tcl && cd /opt/tcl
curl -OL http://prdownloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz
tar xvf tcl8.6.13-src.tar.gz
cd tcl8.6.13/unix
./configure --enable-threads --enable-shared --enable-symbols
make
make install
  • 下载并安装TK
mkdir /opt/tk && cd /opt/tk
curl -OL http://prdownloads.sourceforge.net/tcl/tk8.6.13-src.tar.gz
tar xvf tk8.6.13-src.tar.gz
cd tk8.6.13/unix
./configure --with-tcl=/opt/tcl/tcl8.6.13/unix/
make
make install
  • 下载并安装Python

注意需要指明TCL/TK编译库的路径。 您还可以通过

export LD_LIBRARY_PATH=/usr/local/lib

设置环境变量

如果您使用Python最新版本的帮助(输入时为3.11.5../configure --help)。它指导您使用以下环境变量:

TCLTK_CFLAGS
              C compiler flags for TCLTK, overriding pkg-config
TCLTK_LIBS  linker flags for TCLTK, overriding pkg-config

我能够使用上述机制构建Python最新版本

mkdir /opt/python37 && cd /opt/python37
curl -OL https://www.python.org/ftp/python/3.7.16/Python-3.7.16.tgz
tar xvf Python-3.7.16.tgz
cd Python-3.7.16
./configure --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions --with-tcltk-includes="-I/usr/local/include" --with-tcltk-libs="-L/usr/local/lib -ltcl8.6 -L/usr/local/lib -ltk8.6"
make -j ${nproc}
make altinstall
© www.soinside.com 2019 - 2024. All rights reserved.