我试图在使用pymatting_aot.aot的Google上运行Python3.8脚本
在我的本地Ubuntu机器上运行这个脚本时,它没有任何问题,但是当我试图在GAE上运行它时,我得到了以下错误:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/pymatting_aot/cc.py", line 21, in <module>
import pymatting_aot.aot
ModuleNotFoundError: No module named 'pymatting_aot.aot'这个github链接:https://github.com/danielgatis/rembg/issues/35,显示了我需要安装python3-dev来通过apt-get install -y python3-dev修复这个问题
我在我的GAE控制台上尝试了sudo apt-get install -y python3-dev,我得到了:
machine is ephemeral and no system-wide change will persist beyond session end.
To suppress this warning, create an empty ~/.cloudshell/no-apt-get-warning file.
The command will automatically proceed in 5 seconds or on any key.
Visit https://cloud.google.com/shell/help for more information.
********************************************************************************
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-dev is already the newest version (3.7.3-1).
0 upgraded, 0 newly installed, 0 to remove and 37 not upgraded.requirements.txt
-f https://download.pytorch.org/whl/torch_stable.html
numpy==1.19.4
torch==1.7.0+cpu
torchvision==0.8.1+cpu
pymatting==1.1.1
scikit-image==0.17.2
waitress==1.4.4
scipy==1.5.4
hsh==1.1.0
flask==1.1.2
filetype==1.0.7
matplotlib==3.1.1
tqdm==4.51.0
requests==2.25.0
fastapi==0.62.0
Pillow==8.0.1
skimage==0.0
uvicorn==0.11.6
gunicorn==20.0.4
python-multipart==0.0.5问题仍然存在,你知道我怎样才能让它发挥作用吗?
发布于 2020-12-26 06:56:24
问题是,pymatting_aot.aot实际上不需要导入,需要首先编译。
您可以先在代码中导入pymatting_aot.cc,或者将此导入到您的Dockerfile中以供应用程序引擎使用,以便容器附带这个预编译的共享对象库来编译模块。
下面简要介绍一下它是如何工作的(或者更确切地说,查看编译后它是如何工作的):
root@dcda6f2673cb:/# pip install pymatting
Collecting pymatting
Downloading PyMatting-1.1.2-py3-none-any.whl (48 kB)
|████████████████████████████████| 48 kB 1.4 MB/s
Collecting numba!=0.49.0
Downloading numba-0.52.0-cp38-cp38-manylinux2014_x86_64.whl (3.2 MB)
|████████████████████████████████| 3.2 MB 2.9 MB/s
Requirement already satisfied: setuptools in /usr/local/lib/python3.8/site-packages (from numba!=0.49.0->pymatting) (51.1.0)
Collecting llvmlite<0.36,>=0.35.0
Downloading llvmlite-0.35.0-cp38-cp38-manylinux2010_x86_64.whl (25.3 MB)
|████████████████████████████████| 25.3 MB 10.9 MB/s
Collecting numpy>=1.16.0
Downloading numpy-1.19.4-cp38-cp38-manylinux2010_x86_64.whl (14.5 MB)
|████████████████████████████████| 14.5 MB 11.3 MB/s
Collecting pillow>=5.2.0
Downloading Pillow-8.0.1-cp38-cp38-manylinux1_x86_64.whl (2.2 MB)
|████████████████████████████████| 2.2 MB 3.8 MB/s
Collecting scipy>=1.1.0
Downloading scipy-1.5.4-cp38-cp38-manylinux1_x86_64.whl (25.8 MB)
|████████████████████████████████| 25.8 MB 12.0 MB/s
Installing collected packages: numpy, llvmlite, scipy, pillow, numba, pymatting
Successfully installed llvmlite-0.35.0 numba-0.52.0 numpy-1.19.4 pillow-8.0.1 pymatting-1.1.2 scipy-1.5.4
root@dcda6f2673cb:/# python
Python 3.8.7 (default, Dec 22 2020, 18:46:25)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymatting_aot.aot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pymatting_aot.aot'
>>> import pymatting_aot.cc
Failed to import ahead-of-time-compiled modules.
This is expected on first import.
Compiling modules and trying again.
This might take a minute.
Successfully imported ahead-of-time-compiled modules.
>>> import pymatting_aot.aot
>>> pymatting_aot.aot
<module 'pymatting_aot.aot' from '/usr/local/lib/python3.8/site-packages/pymatting_aot/aot.cpython-38-x86_64-linux-gnu.so'>编辑1:实际上,在查看了cc.py之后,您甚至不需要在导入pymatting_aot.cc之后导入pymatting_aot.aot,因为它将为您加载。
编辑2:下面是如何为应用程序引擎的自定义flex env嵌入从Dockerfile编译.so的方法:
~ cat Dockerfile
FROM python:3.8
RUN pip install pymatting && python -c 'import pymatting_aot.cc'测试:
~ docker run -it --rm test:latest
Python 3.8.7 (default, Dec 22 2020, 18:46:25)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymatting_aot.aot
>>>发布于 2020-12-25 02:45:00
如果你还没解决,试试
apt-get install python3.8-dev发布于 2020-12-24 04:44:13
尝试在GAE中安装pymatting
pip3 install pymattinghttps://stackoverflow.com/questions/65434003
复制相似问题