gpt4 book ai didi

python - 为 Python 安装准备 _tkinter 和 sqlite3(无管理员权限)

转载 作者:行者123 更新时间:2023-12-04 19:09:58 25 4
gpt4 key购买 nike

我正在尝试直接从源代码构建 Python,没有管理员权限,运行后:

export CPPFLAGS='-I/opt/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
-I/opt/tcl8.6.0/include/'

export LDFLAGS='-L/opt/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/
-L/opt/tcl8.6.0/lib/ ./configure --prefix=/path_to_python-2.7.4 --enable-shared'



进而
make

我得到以下信息:

building '_tkinter' extension

gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c /opt/python/src/Python-2.7.4/Modules/_tkinter.c -o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o

gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c /opt/python/src/Python-2.7.4/Modules/tkappinit.c -o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o

gcc -pthread -shared -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o -L/usr/X11/lib -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/usr/local/lib -L. -ltk8.6 -ltcl8.6 -lX11 -lpython2.7 -o build/lib.linux-x86_64-2.7/_tkinter.so

* WARNING: renaming "_tkinter" since importing it failed: libtk8.6.so: cannot open shared object file: No such file or directory



奇怪的是我可以看到 libtk8.6.so .它实际上就在 /opt/tcl8.6.0/lib 下正如我指定的 LDFLAGS .

为什么编译失败?

最佳答案

此问题发生在安装过程中 setup.py , 当 Python 尝试导入 _tkinter .如果你看一下函数build_extension ,有一个 block 说:

imp.load_dynamic(ext.name, ext_filename)

此行尝试动态加载 _tkinter (使用动态共享库 libtk8.6.so )。因此,即使编译/链接工作正常,当 Python 测试模块时,它使用动态库,我在 LD_LIBRARY_PATH 中没有 tcl/lib 或 tk/lib .一旦我添加了这些,一切都很好。

总之:
我必须通过 CPPFLAGS 添加以下包含路径
  • /path_to/sqlite3/include
  • /path_to/tcl/include
  • /path_to/tk/include

  • 以下库路径通过 LDFLAGS
  • /path_to/sqlite3/lib
  • /path_to/tcl/lib
  • /path_to/tk/lib

  • 以及通过 LD_LIBRARY_PATH 的以下库路径:
  • /path_to/sqlite3/lib
  • /path_to/tcl/lib
  • /path_to/tk/lib

  • 有了这一切,一切正常。

    关于python - 为 Python 安装准备 _tkinter 和 sqlite3(无管理员权限),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16026348/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com