Skip to main content
 首页 » 编程设计

Python dev_appserver 无法导入 `.so` 文件(枕头)

2025年02月15日21davidwang456

在我的 GAE 应用程序中,我尝试这样做:

from PIL import Image 

得到这个:

Traceback (most recent call last): 
  ... 
  File "/home/sheena/Workspace/Waxed/code/waxed_backend/src/waxed_backend/concerns/misc/views.py", line 57, in home 
    from PIL import Image 
  File "libs/PIL/Image.py", line 56, in <module> 
    from . import _imaging as core 
  File "/home/sheena/Workspace/Waxed/venvs/wxt_comp/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 1024, in load_module 
    raise ImportError('No module named %s' % fullname) 
ImportError: No module named PIL._imaging 

/path/to/libs/PIL/imaging.so 存在。而且我从 dev_appserver 中的 libs 文件导入任何其他东西都没有问题。

这很好用:

cd /path/to/libs/ 
python 
>>> from PIL import Image 

我只能得出结论,dev_appserver 以某种方式破坏了 importrt 功能,因此无法识别 .so 文件。

有没有人见过这个?知道如何解决吗?

请您参考如下方法:

_imaging 是一个用 C 编写的 PIL 依赖项。因为它是 C 而不是 Python,所以将库包含在您的 lib 文件夹中将不起作用。您需要在 app.yaml 文件中定义该库:

libraries: 
   - name: PIL 
     version: latest