ModuleNotFoundError: No module named 'aiohttp'
ModuleNotFoundError: No module named 'aiohttp'
的解决方法
使用 azure web app(linux) 计划,linux_fx_version 是 Python|3.7
我的requirement.txt是
botbuilder_schema==4.13.0
requests==2.25.0
aiohttp==3.7.4
botbuilder==0.0.1
botbuilder-core==4.13.0
botbuilder-dialogs==4.13.0
当我尝试执行 zip deploy(az webapp deployment source config-zip
) 时,部署进展顺利 - 使用 Kudo zip deploy,除了在启动我的应用程序时它给出错误 liks module not found aiohttp
错误日志:
2021-06-28T07:35:59.154876250Z Build Operation ID: 58418482-e3f1-4f4f-8f3f-23c89fdc7228
2021-06-28T07:36:00.652990532Z Oryx Version: 0.2.20210420.1, Commit: 85c6e9278aae3980b86cb1d520aaad532c814ed7, ReleaseTagName: 20210420.1
2021-06-28T07:36:01.268742028Z Detected an app based on Flask
2021-06-28T07:36:01.270392332Z Generating `gunicorn` command for 'app:app'
2021-06-28T07:36:01.451069287Z Writing output script to '/opt/startup/startup.sh'
2021-06-28T07:36:01.897311466Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2021-06-28T07:36:01.897342966Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2021-06-28T07:36:02.714252775Z [2021-06-28 07:36:02 +0000] [35] [INFO] Starting gunicorn 20.1.0
2021-06-28T07:36:02.715401977Z [2021-06-28 07:36:02 +0000] [35] [INFO] Listening at: http://0.0.0.0:8000 (35)
2021-06-28T07:36:02.715816178Z [2021-06-28 07:36:02 +0000] [35] [INFO] Using worker: sync
2021-06-28T07:36:02.725130896Z [2021-06-28 07:36:02 +0000] [38] [INFO] Booting worker with pid: 38
2021-06-28T07:36:02.757363360Z [2021-06-28 07:36:02 +0000] [38] [ERROR] Exception in worker process
2021-06-28T07:36:02.757382760Z Traceback (most recent call last):
2021-06-28T07:36:02.757439960Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-28T07:36:02.757446560Z worker.init_process()
2021-06-28T07:36:02.757450260Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-28T07:36:02.757463360Z self.load_wsgi()
2021-06-28T07:36:02.757467260Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-28T07:36:02.757470560Z self.wsgi = self.app.wsgi()
2021-06-28T07:36:02.757473760Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-28T07:36:02.757477360Z self.callable = self.load()
2021-06-28T07:36:02.757480460Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-28T07:36:02.757483660Z return self.load_wsgiapp()
2021-06-28T07:36:02.757486760Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-28T07:36:02.757489960Z return util.import_app(self.app_uri)
2021-06-28T07:36:02.757493160Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-28T07:36:02.845882934Z mod = importlib.import_module(module)
2021-06-28T07:36:02.845888734Z File "/opt/python/3.7.9/lib/python3.7/importlib/__init__.py", line 127, in import_module
2021-06-28T07:36:02.845892434Z return _bootstrap._gcd_import(name[level:], package, level)
2021-06-28T07:36:02.845895934Z File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
2021-06-28T07:36:02.845899934Z File "<frozen importlib._bootstrap>", line 983, in _find_and_load
2021-06-28T07:36:02.845903534Z File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
2021-06-28T07:36:02.845906934Z File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
2021-06-28T07:36:02.845910134Z File "<frozen importlib._bootstrap_external>", line 728, in exec_module
2021-06-28T07:36:02.845913434Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-28T07:36:02.845924834Z File "/home/site/wwwroot/app.py", line 5, in <module>
2021-06-28T07:36:02.845929234Z from aiohttp import web
2021-06-28T07:36:02.845932334Z ModuleNotFoundError: No module named 'aiohttp'
2021-06-28T07:36:02.845936534Z [2021-06-28 07:36:02 +0000] [38] [INFO] Worker exiting (pid: 38)
2021-06-28T07:36:02.866740775Z [2021-06-28 07:36:02 +0000] [35] [INFO] Shutting down: Master
2021-06-28T07:36:02.867504676Z [2021-06-28 07:36:02 +0000] [35] [INFO] Reason: Worker failed to boot.
我尝试了不同版本的 aiohttp
,request
甚至增加了 Python 3.8
目前没有任何效果。
可能是您使用的是 pip
而不是 pip3
。
尝试使用 pip3 install -r requirements.txt
.
安装依赖项
另一件需要注意的事情是,如果您使用的是 virtual environment
,您还需要在其中安装依赖项。
所以有很多事情可以帮助我解决问题。
默认情况下,Kudu 假定 zip 部署不需要任何与构建相关的操作,如 npm install
或 dotnet publish
。因此,这种情况下的原因可能是 pip installation
没有得到妥善处理。
要让它自动安装requirements.txt文件中所有需要的包,我们可以简单地在appsettings中将SCM_DO_BUILD_DURING_DEPLOYMENT
设置为true
,然后再次部署。
需要设置启动命令如
gunicorn --bind 0.0.0.0 --worker-class aiohttp.worker.GunicornWebWorker --timeout 600 app:APP
正确配置 MicrosoftAppId
和 MicrosoftAppPassword
使用 azure web app(linux) 计划,linux_fx_version 是 Python|3.7
我的requirement.txt是
botbuilder_schema==4.13.0
requests==2.25.0
aiohttp==3.7.4
botbuilder==0.0.1
botbuilder-core==4.13.0
botbuilder-dialogs==4.13.0
当我尝试执行 zip deploy(az webapp deployment source config-zip
) 时,部署进展顺利 - 使用 Kudo zip deploy,除了在启动我的应用程序时它给出错误 liks module not found aiohttp
错误日志:
2021-06-28T07:35:59.154876250Z Build Operation ID: 58418482-e3f1-4f4f-8f3f-23c89fdc7228
2021-06-28T07:36:00.652990532Z Oryx Version: 0.2.20210420.1, Commit: 85c6e9278aae3980b86cb1d520aaad532c814ed7, ReleaseTagName: 20210420.1
2021-06-28T07:36:01.268742028Z Detected an app based on Flask
2021-06-28T07:36:01.270392332Z Generating `gunicorn` command for 'app:app'
2021-06-28T07:36:01.451069287Z Writing output script to '/opt/startup/startup.sh'
2021-06-28T07:36:01.897311466Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2021-06-28T07:36:01.897342966Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2021-06-28T07:36:02.714252775Z [2021-06-28 07:36:02 +0000] [35] [INFO] Starting gunicorn 20.1.0
2021-06-28T07:36:02.715401977Z [2021-06-28 07:36:02 +0000] [35] [INFO] Listening at: http://0.0.0.0:8000 (35)
2021-06-28T07:36:02.715816178Z [2021-06-28 07:36:02 +0000] [35] [INFO] Using worker: sync
2021-06-28T07:36:02.725130896Z [2021-06-28 07:36:02 +0000] [38] [INFO] Booting worker with pid: 38
2021-06-28T07:36:02.757363360Z [2021-06-28 07:36:02 +0000] [38] [ERROR] Exception in worker process
2021-06-28T07:36:02.757382760Z Traceback (most recent call last):
2021-06-28T07:36:02.757439960Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-28T07:36:02.757446560Z worker.init_process()
2021-06-28T07:36:02.757450260Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-28T07:36:02.757463360Z self.load_wsgi()
2021-06-28T07:36:02.757467260Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-28T07:36:02.757470560Z self.wsgi = self.app.wsgi()
2021-06-28T07:36:02.757473760Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-28T07:36:02.757477360Z self.callable = self.load()
2021-06-28T07:36:02.757480460Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-28T07:36:02.757483660Z return self.load_wsgiapp()
2021-06-28T07:36:02.757486760Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-28T07:36:02.757489960Z return util.import_app(self.app_uri)
2021-06-28T07:36:02.757493160Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-28T07:36:02.845882934Z mod = importlib.import_module(module)
2021-06-28T07:36:02.845888734Z File "/opt/python/3.7.9/lib/python3.7/importlib/__init__.py", line 127, in import_module
2021-06-28T07:36:02.845892434Z return _bootstrap._gcd_import(name[level:], package, level)
2021-06-28T07:36:02.845895934Z File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
2021-06-28T07:36:02.845899934Z File "<frozen importlib._bootstrap>", line 983, in _find_and_load
2021-06-28T07:36:02.845903534Z File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
2021-06-28T07:36:02.845906934Z File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
2021-06-28T07:36:02.845910134Z File "<frozen importlib._bootstrap_external>", line 728, in exec_module
2021-06-28T07:36:02.845913434Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-28T07:36:02.845924834Z File "/home/site/wwwroot/app.py", line 5, in <module>
2021-06-28T07:36:02.845929234Z from aiohttp import web
2021-06-28T07:36:02.845932334Z ModuleNotFoundError: No module named 'aiohttp'
2021-06-28T07:36:02.845936534Z [2021-06-28 07:36:02 +0000] [38] [INFO] Worker exiting (pid: 38)
2021-06-28T07:36:02.866740775Z [2021-06-28 07:36:02 +0000] [35] [INFO] Shutting down: Master
2021-06-28T07:36:02.867504676Z [2021-06-28 07:36:02 +0000] [35] [INFO] Reason: Worker failed to boot.
我尝试了不同版本的 aiohttp
,request
甚至增加了 Python 3.8
目前没有任何效果。
可能是您使用的是 pip
而不是 pip3
。
尝试使用 pip3 install -r requirements.txt
.
另一件需要注意的事情是,如果您使用的是 virtual environment
,您还需要在其中安装依赖项。
所以有很多事情可以帮助我解决问题。
默认情况下,Kudu 假定 zip 部署不需要任何与构建相关的操作,如
npm install
或dotnet publish
。因此,这种情况下的原因可能是pip installation
没有得到妥善处理。要让它自动安装requirements.txt文件中所有需要的包,我们可以简单地在appsettings中将
SCM_DO_BUILD_DURING_DEPLOYMENT
设置为true
,然后再次部署。需要设置启动命令如
gunicorn --bind 0.0.0.0 --worker-class aiohttp.worker.GunicornWebWorker --timeout 600 app:APP
正确配置
MicrosoftAppId
和MicrosoftAppPassword