You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

已编译TDLib,运行Python示例时提示找不到tdjson.dll的问题求助

Fixing "tdjson.dll: cannot open shared object file" in Python with TDLib on Linux

First off, notice the key mismatch here: you’re on a Linux system (evident from /usr/lib/python2.7 in the traceback), but your script is trying to load a .dll file—those are Windows dynamic libraries. On Linux, TDLib compiles to a .so (shared object) file instead. Here’s how to fix this:

Step 1: Locate your compiled TDLib shared library

After compiling TDLib, check your build directory (usually td/build if you followed the repo’s instructions) for a file named either libtdjson.so or tdjson.so. That’s the correct library file to use on Linux.

Step 2: Update your Python script to point to the .so file

In tdjson_example.py, modify the tdjson_path variable to target this .so file instead of tdjson.dll. For example:

tdjson_path = "/path/to/your/td/build/libtdjson.so"
tdjson = CDLL(tdjson_path)

Step 3: Ensure the linker can find the library (if using relative paths or system-wide installation)

If you don’t want to use the full absolute path, you have two solid options:

  • Temporarily add the library directory to LD_LIBRARY_PATH:
    Run your script like this:
    LD_LIBRARY_PATH=/path/to/td/build python tdjson_example.py
    
  • Install the library system-wide:
    Copy the libtdjson.so file to /usr/local/lib, then run:
    sudo ldconfig
    
    After this, you can simplify your script to just tdjson = CDLL("libtdjson.so") without specifying the full path.

Verify the fix

Once you’ve updated the path and ensured the linker can locate the library, re-run your script. The error should be resolved if everything is set correctly.

Traceback (most recent call last):
File "tdjson_example.py", line 10, in
tdjson = CDLL(tdjson_path)
File "/usr/lib/python2.7/ctypes/init.py", line 365, in init
self._handle = _dlopen(self._name, mode)
OSError: tdjson.dll: cannot open shared object file: No such file or directory

内容的提问来源于stack exchange,提问作者Nikolay

火山引擎 最新活动