我已经编写了代码来压缩 .py 文件中的图像,并尝试使用 transcrypt 进行编译以转换为 JS 文件。在此过程中,我收到以下错误(屏幕截图)但是如果我使用 IDE 单独运行 .py 文件,它可以正常工作并压缩图像。
代码:
import PIL
from PIL import Image as pil
class FileUpload:
def Images (self,arg):
# Open the image
im = pil.open(arg)
# Now save it
im.save("img_compressed.jpg", format="JPEG", quality=90)
fileupload = FileUpload()
错误 :
\python src\imgcompress>python -m transcrypt -b -m -n imageCompress.py
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.6.101
Copyright (C) Geatec Engineering. License: Apache 2.0
Error while compiling (offending file last):
File '/python src/imgcompress/imageCompress.py', line 1, at import of:
File '/python/lib/site-packages/PIL/__init__.py', line 14, namely:
Can't import module 'PIL'
Aborted