ModuleNotFoundError: No module named ‘cv2’ in Python

Kevin Zhu 26 Reputation points
2020-10-15T15:26:10.403+00:00

32713-image.png

Currently experiencing an error with Azure and it's telling me that I have an import error: "ImportError: libGL.so.1: cannot open shared object file: No such file or directory", but I don't understand what this means. Before I got this error message, it said that there was a ModuleError, as it couldn't find cv2. My Flask App deployed successfully shown in my deployment center (fig 2) 32706-image.png. In my requirements.txt file, all the versions are up to date and I have checked for compatibility, but nothing is working. Please help

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,493 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ryan Hill 24,216 Reputation points Microsoft Employee
    2020-10-20T19:00:22.567+00:00

    Hi @Kevin Zhu ,

    Thanks for providing the blog post you provided. I did encounter similar issues when I deployed your code using VS Code or using az webapp up where it doesn't appear the pip install -r requirements.txt ran. I'm still investigating that as I'm having errors using SSH where I can activate the antenv virtual environment to install the modules manually. If I find anything out, I'll post a comment below.

    In the meantime, what was successful was a local to Azure kudu deployment. I also added a gunicorn --bind=0.0.0.0 --timeout 600 main:app as the startup command as the python container for Linux app plans will check for app.py, application.py, index.py, or server.py. Using remote git deployment does run the requirements.txt install and I didn't encounter a module missing error message.

    2020-10-20T17:08:28.239610531Z   
    2020-10-20T17:08:28.239666532Z   _____                                 
    2020-10-20T17:08:28.239670732Z   /  _  \ __________ _________   ____    
    2020-10-20T17:08:28.239673733Z  /  /_\  \___   /  |  \_  __ \_/ __ \   
    2020-10-20T17:08:28.239676833Z /    |    \/    /|  |  /|  | \/\  ___/   
    2020-10-20T17:08:28.239679833Z \____|__  /_____ \____/ |__|    \___  >  
    2020-10-20T17:08:28.239683033Z         \/      \/                  \/   
    2020-10-20T17:08:28.239685833Z   
    2020-10-20T17:08:28.239688433Z A P P   S E R V I C E   O N   L I N U X  
    2020-10-20T17:08:28.239691133Z   
    2020-10-20T17:08:28.239693733Z Documentation: http://aka.ms/webapp-linux  
    2020-10-20T17:08:28.239696333Z Python 3.8.3  
    2020-10-20T17:08:28.239699033Z Note: Any data outside '/home' is not persisted  
    2020-10-20T17:08:28.410897565Z Starting OpenBSD Secure Shell server: sshd.  
    2020-10-20T17:08:28.440689410Z Site's appCommandLine: gunicorn --bind=0.0.0.0 --timeout 600 main:app  
    2020-10-20T17:08:28.448049145Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn --bind=0.0.0.0 --timeout 600 main:app'  
    2020-10-20T17:08:28.931488590Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...  
    2020-10-20T17:08:28.934802351Z Build Operation ID: |tc7O2SA6YJg=.65326840_  
    2020-10-20T17:08:28.936602784Z Oryx Version: 0.2.20200706.2, Commit: 42be45d884938c3c818ba08e9e4760b1136fd9b3, ReleaseTagName: 20200706.2  
    2020-10-20T17:08:30.201902348Z Writing output script to '/opt/startup/startup.sh'  
    2020-10-20T17:08:30.871902316Z Found virtual environment .tar.gz archive.  
    2020-10-20T17:08:30.872456326Z Removing existing virtual environment directory /antenv...  
    2020-10-20T17:08:30.880607176Z Extracting to directory /antenv...  
    2020-10-20T17:09:15.300257667Z Using packages from virtual environment antenv located at /antenv.  
    2020-10-20T17:09:15.300671175Z Updated PYTHONPATH to ':/antenv/lib/python3.8/site-packages'  
    2020-10-20T17:09:16.798163937Z [2020-10-20 17:09:16 +0000] [40] [INFO] Starting gunicorn 20.0.4  
    2020-10-20T17:09:16.799495262Z [2020-10-20 17:09:16 +0000] [40] [INFO] Listening at: http://0.0.0.0:8000 (40)  
    2020-10-20T17:09:16.800149474Z [2020-10-20 17:09:16 +0000] [40] [INFO] Using worker: sync  
    2020-10-20T17:09:16.817605998Z [2020-10-20 17:09:16 +0000] [42] [INFO] Booting worker with pid: 42  
    

    Deployment logs:

    2020-10-20T16:57:45.342Z - Updating branch 'master'.  
    2020-10-20T16:57:46.190Z - Updating submodules.  
    2020-10-20T16:57:46.230Z - Preparing deployment for commit id 'bb08b83187'.  
    2020-10-20T16:57:46.362Z - Repository path is /home/site/repository  
    2020-10-20T16:57:46.403Z - Running oryx build...  
    2020-10-20T16:57:46.413Z - Command: oryx build /home/site/repository -o /home/site/wwwroot --platform python --platform-version 3.8 -i /tmp/8d8751944dd0965 -p compress_virtualenv=tar-gz -p virtualenv_name=antenv --log-file /tmp/build-debug.log   
    2020-10-20T16:57:51.526Z - Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx  
    2020-10-20T16:57:51.597Z - You can report issues at https://github.com/Microsoft/Oryx/issues  
    2020-10-20T16:57:51.633Z - Oryx Version: 0.2.20200805.1, Commit: e7c39ede513143e9d80fd553f106f04268d770d4, ReleaseTagName: 20200805.1  
    2020-10-20T16:57:51.653Z - Build Operation ID: |tc7O2SA6YJg=.65326840_  
    2020-10-20T16:57:51.674Z - Repository Commit : bb08b83187ab5a49522a7c4df0661425177c49d9  
    2020-10-20T16:57:51.698Z - Detecting platforms...  
    2020-10-20T16:57:52.033Z - Detected following platforms:  
    2020-10-20T16:57:52.059Z -   python: 3.8.4  
    2020-10-20T16:57:52.467Z - Using intermediate directory '/tmp/8d8751944dd0965'.  
    2020-10-20T16:57:52.531Z - Copying files to the intermediate directory...  
    2020-10-20T16:57:52.848Z - Done in 0 sec(s).  
    2020-10-20T16:57:52.991Z - Source directory     : /tmp/8d8751944dd0965  
    2020-10-20T16:57:53.031Z - Destination directory: /home/site/wwwroot  
    2020-10-20T16:57:53.441Z - Python Version: /opt/python/3.8.4/bin/python3.8  
    2020-10-20T16:57:53.451Z - Python Virtual Environment: antenv  
    2020-10-20T16:57:53.460Z - Creating virtual environment...  
    2020-10-20T16:58:08.820Z - Activating virtual environment...  
    2020-10-20T16:58:08.911Z - Running pip install...  
    2020-10-20T16:58:10.695Z - [16:58:10+0000] Collecting app==0.0.1  
    2020-10-20T16:58:10.763Z - [16:58:10+0000]   Downloading app-0.0.1.zip (2.2 kB)  
    2020-10-20T16:58:11.666Z - [16:58:11+0000] Collecting argh==0.26.2  
    2020-10-20T16:58:11.691Z - [16:58:11+0000]   Downloading argh-0.26.2-py2.py3-none-any.whl (30 kB)  
    2020-10-20T16:58:11.818Z - [16:58:11+0000] Collecting click==7.1.2  
    2020-10-20T16:58:11.841Z - [16:58:11+0000]   Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)  
    2020-10-20T16:58:11.930Z - [16:58:11+0000] Collecting cycler==0.10.0  
    2020-10-20T16:58:11.949Z - [16:58:11+0000]   Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)  
    2020-10-20T16:58:12.025Z - [16:58:12+0000] Collecting DateTime==4.3  
    2020-10-20T16:58:12.043Z - [16:58:12+0000]   Downloading DateTime-4.3-py2.py3-none-any.whl (60 kB)  
    2020-10-20T16:58:12.163Z - [16:58:12+0000] Collecting decorator==4.4.2  
    2020-10-20T16:58:12.186Z - [16:58:12+0000]   Downloading decorator-4.4.2-py2.py3-none-any.whl (9.2 kB)  
    2020-10-20T16:58:12.298Z - [16:58:12+0000] Collecting Flask==1.1.2  
    2020-10-20T16:58:12.317Z - [16:58:12+0000]   Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)  
    2020-10-20T16:58:12.447Z - [16:58:12+0000] Collecting Flask-Images==3.0.2  
    2020-10-20T16:58:12.461Z - [16:58:12+0000]   Downloading Flask-Images-3.0.2.tar.gz (10 kB)  
    2020-10-20T16:58:13.371Z - [16:58:13+0000] Collecting Flask-Resize==2.0.4  
    2020-10-20T16:58:13.454Z - [16:58:13+0000]   Downloading Flask_Resize-2.0.4-py2.py3-none-any.whl (53 kB)  
    2020-10-20T16:58:13.574Z - [16:58:13+0000] Collecting Flask-SQLAlchemy==2.4.4  
    2020-10-20T16:58:13.594Z - [16:58:13+0000]   Downloading Flask_SQLAlchemy-2.4.4-py2.py3-none-any.whl (17 kB)  
    2020-10-20T16:58:13.685Z - [16:58:13+0000] Collecting imageio==2.9.0  
    2020-10-20T16:58:13.718Z - [16:58:13+0000]   Downloading imageio-2.9.0-py3-none-any.whl (3.3 MB)  
    2020-10-20T16:58:14.885Z - [16:58:14+0000] Collecting itsdangerous==1.1.0  
    2020-10-20T16:58:14.908Z - [16:58:14+0000]   Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)  
    2020-10-20T16:58:15.006Z - [16:58:15+0000] Collecting Jinja2==2.11.2  
    2020-10-20T16:58:15.025Z - [16:58:15+0000]   Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)  
    2020-10-20T16:58:15.167Z - [16:58:15+0000] Collecting kiwisolver==1.2.0  
    2020-10-20T16:58:15.185Z - [16:58:15+0000]   Downloading kiwisolver-1.2.0-cp38-cp38-manylinux1_x86_64.whl (92 kB)  
    2020-10-20T16:58:15.261Z - [16:58:15+0000] Collecting livereload==2.6.3  
    2020-10-20T16:58:15.287Z - [16:58:15+0000]   Downloading livereload-2.6.3.tar.gz (25 kB)  
    2020-10-20T16:58:16.206Z - [16:58:16+0000] Collecting MarkupSafe==1.1.1  
    2020-10-20T16:58:16.231Z - [16:58:16+0000]   Downloading MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl (32 kB)  
    2020-10-20T16:58:16.714Z - [16:58:16+0000] Collecting matplotlib==3.3.2  
    2020-10-20T16:58:16.733Z - [16:58:16+0000]   Downloading matplotlib-3.3.2-cp38-cp38-manylinux1_x86_64.whl (11.6 MB)  
    2020-10-20T16:58:27.117Z - [16:58:27+0000] Collecting numpy==1.19.2  
    2020-10-20T16:58:27.168Z - [16:58:27+0000]   Downloading numpy-1.19.2-cp38-cp38-manylinux2010_x86_64.whl (14.5 MB)  
    2020-10-20T16:58:35.905Z - [16:58:35+0000] Collecting opencv-contrib-python==4.4.0.44  
    2020-10-20T16:58:35.935Z - [16:58:35+0000]   Downloading opencv_contrib_python-4.4.0.44-cp38-cp38-manylinux2014_x86_64.whl (55.7 MB)  
    2020-10-20T16:59:08.850Z - [16:59:08+0000] Collecting opencv-python-headless==4.4.0.44  
    2020-10-20T16:59:08.882Z - [16:59:08+0000]   Downloading opencv_python_headless-4.4.0.44-cp38-cp38-manylinux2014_x86_64.whl (36.7 MB)  
    2020-10-20T16:59:31.083Z - [16:59:31+0000] Collecting pilkit==2.0  
    2020-10-20T16:59:31.134Z - [16:59:31+0000]   Downloading pilkit-2.0.tar.gz (161 kB)  
    2020-10-20T16:59:34.267Z - [16:59:34+0000] Collecting Pillow==7.2.0  
    2020-10-20T16:59:34.376Z - [16:59:34+0000]   Downloading Pillow-7.2.0-cp38-cp38-manylinux1_x86_64.whl (2.2 MB)  
    2020-10-20T16:59:35.142Z - [16:59:35+0000] Collecting pillowcase==2.0.0  
    2020-10-20T16:59:35.167Z - [16:59:35+0000]   Downloading pillowcase-2.0.0.tar.gz (1.2 kB)  
    2020-10-20T16:59:36.083Z - [16:59:36+0000] Collecting pyparsing==2.4.7  
    2020-10-20T16:59:36.109Z - [16:59:36+0000]   Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)  
    2020-10-20T16:59:36.214Z - [16:59:36+0000] Collecting python-dateutil==2.8.1  
    2020-10-20T16:59:36.234Z - [16:59:36+0000]   Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)  
    2020-10-20T16:59:36.655Z - [16:59:36+0000] Collecting pytz==2020.1  
    2020-10-20T16:59:36.717Z - [16:59:36+0000]   Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)  
    2020-10-20T16:59:40.220Z - [16:59:40+0000] Collecting PyWavelets==1.1.1  
    2020-10-20T16:59:40.261Z - [16:59:40+0000]   Downloading PyWavelets-1.1.1-cp38-cp38-manylinux1_x86_64.whl (4.4 MB)  
    2020-10-20T16:59:41.293Z - [16:59:41+0000] Collecting scikit-image==0.17.2  
    2020-10-20T16:59:41.342Z - [16:59:41+0000]   Downloading scikit_image-0.17.2-cp38-cp38-manylinux1_x86_64.whl (12.4 MB)  
    2020-10-20T16:59:44.604Z - [16:59:44+0000] Collecting scipy==1.5.2  
    2020-10-20T16:59:44.645Z - [16:59:44+0000]   Downloading scipy-1.5.2-cp38-cp38-manylinux1_x86_64.whl (25.7 MB)  
    2020-10-20T17:00:08.814Z - [17:00:08+0000] Collecting Werkzeug==1.0.1  
    2020-10-20T17:00:08.843Z - [17:00:08+0000]   Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)  
    2020-10-20T17:00:09.946Z - [17:00:09+0000] Collecting zope.interface==5.1.0  
    2020-10-20T17:00:09.977Z - [17:00:09+0000]   Downloading zope.interface-5.1.0-cp38-cp38-manylinux2010_x86_64.whl (243 kB)  
    2020-10-20T17:00:10.206Z - [17:00:10+0000] Collecting six  
    2020-10-20T17:00:10.297Z - [17:00:10+0000]   Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)  
    2020-10-20T17:00:11.292Z - [17:00:11+0000] Collecting SQLAlchemy>=0.8.0  
    2020-10-20T17:00:11.389Z - [17:00:11+0000]   Downloading SQLAlchemy-1.3.20-cp38-cp38-manylinux2010_x86_64.whl (1.3 MB)  
    2020-10-20T17:00:11.894Z - [17:00:11+0000] Collecting tornado  
    2020-10-20T17:00:11.915Z - [17:00:11+0000]   Downloading tornado-6.0.4.tar.gz (496 kB)  
    2020-10-20T17:00:13.218Z - [17:00:13+0000] Collecting certifi>=2020.06.20  
    2020-10-20T17:00:13.253Z - [17:00:13+0000]   Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)  
    2020-10-20T17:00:13.388Z - [17:00:13+0000] Collecting networkx>=2.0  
    2020-10-20T17:00:13.418Z - [17:00:13+0000]   Downloading networkx-2.5-py3-none-any.whl (1.6 MB)  
    2020-10-20T17:00:15.018Z - [17:00:15+0000] Collecting tifffile>=2019.7.26  
    2020-10-20T17:00:15.098Z - [17:00:15+0000]   Downloading tifffile-2020.10.1-py3-none-any.whl (152 kB)  
    2020-10-20T17:00:15.245Z - [17:00:15+0000] Requirement already satisfied: setuptools in ./antenv/lib/python3.8/site-packages (from zope.interface==5.1.0->-r requirements.txt (line 38)) (47.1.0)  
    2020-10-20T17:00:15.312Z - [17:00:15+0000] Using legacy setup.py install for app, since package 'wheel' is not installed.  
    2020-10-20T17:00:15.335Z - [17:00:15+0000] Using legacy setup.py install for Flask-Images, since package 'wheel' is not installed.  
    2020-10-20T17:00:15.391Z - [17:00:15+0000] Using legacy setup.py install for livereload, since package 'wheel' is not installed.  
    2020-10-20T17:00:15.421Z - [17:00:15+0000] Using legacy setup.py install for pilkit, since package 'wheel' is not installed.  
    2020-10-20T17:00:15.481Z - [17:00:15+0000] Using legacy setup.py install for pillowcase, since package 'wheel' is not installed.  
    2020-10-20T17:00:15.544Z - [17:00:15+0000] Using legacy setup.py install for tornado, since package 'wheel' is not installed.  
    2020-10-20T17:00:18.165Z - [17:00:18+0000] Installing collected packages: app, argh, click, six, cycler, zope.interface, pytz, DateTime, decorator, MarkupSafe, Jinja2, Werkzeug, itsdangerous, Flask, Pillow, pillowcase, Flask-Images, pilkit, Flask-Resize, SQLAlchemy, Flask-SQLAlchemy, numpy, imageio, kiwisolver, tornado, livereload, pyparsing, python-dateutil, certifi, matplotlib, opencv-contrib-python, opencv-python-headless, PyWavelets, networkx, tifffile, scipy, scikit-image  
    2020-10-20T17:00:18.264Z - [17:00:18+0000]     Running setup.py install for app: started  
    2020-10-20T17:00:20.140Z - [17:00:20+0000]     Running setup.py install for app: finished with status 'done'  
    2020-10-20T17:00:25.238Z - [17:00:25+0000]     Running setup.py install for pillowcase: started  
    2020-10-20T17:00:26.687Z - [17:00:26+0000]     Running setup.py install for pillowcase: finished with status 'done'  
    2020-10-20T17:00:26.725Z - [17:00:26+0000]     Running setup.py install for Flask-Images: started  
    2020-10-20T17:00:27.706Z - [17:00:27+0000]     Running setup.py install for Flask-Images: finished with status 'done'  
    2020-10-20T17:00:27.759Z - [17:00:27+0000]     Running setup.py install for pilkit: started  
    2020-10-20T17:00:28.706Z - [17:00:28+0000]     Running setup.py install for pilkit: finished with status 'done'  
    2020-10-20T17:00:54.531Z - [17:00:54+0000]     Running setup.py install for tornado: started  
    2020-10-20T17:01:04.431Z - [17:01:04+0000]     Running setup.py install for tornado: finished with status 'done'  
    2020-10-20T17:01:04.707Z - [17:01:04+0000]     Running setup.py install for livereload: started  
    2020-10-20T17:01:05.771Z - [17:01:05+0000]     Running setup.py install for livereload: finished with status 'done'  
    2020-10-20T17:02:53.479Z - [17:02:53+0000] Successfully installed DateTime-4.3 Flask-1.1.2 Flask-Images-3.0.2 Flask-Resize-2.0.4 Flask-SQLAlchemy-2.4.4 Jinja2-2.11.2 MarkupSafe-1.1.1 Pillow-7.2.0 PyWavelets-1.1.1 SQLAlchemy-1.3.20 Werkzeug-1.0.1 app-0.0.1 argh-0.26.2 certifi-2020.6.20 click-7.1.2 cycler-0.10.0 decorator-4.4.2 imageio-2.9.0 itsdangerous-1.1.0 kiwisolver-1.2.0 livereload-2.6.3 matplotlib-3.3.2 networkx-2.5 numpy-1.19.2 opencv-contrib-python-4.4.0.44 opencv-python-headless-4.4.0.44 pilkit-2.0 pillowcase-2.0.0 pyparsing-2.4.7 python-dateutil-2.8.1 pytz-2020.1 scikit-image-0.17.2 scipy-1.5.2 six-1.15.0 tifffile-2020.10.1 tornado-6.0.4 zope.interface-5.1.0  
    2020-10-20T17:03:00.666Z - WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.  
    2020-10-20T17:03:00.725Z - You should consider upgrading via the '/tmp/8d8751944dd0965/antenv/bin/python -m pip install --upgrade pip' command.  
    2020-10-20T17:03:01.489Z - Compressing existing 'antenv' folder...  
    2020-10-20T17:04:18.411Z - Done in 77 sec(s).  
    2020-10-20T17:04:19.653Z - Copying files to destination directory '/home/site/wwwroot'...  
    2020-10-20T17:04:27.528Z - Done in 9 sec(s).  
    2020-10-20T17:04:28.599Z - Removing existing manifest file  
    2020-10-20T17:04:28.624Z - Creating a manifest file...  
    2020-10-20T17:04:28.653Z - Manifest file created.  
    2020-10-20T17:04:28.673Z - Done in 396 sec(s).  
    2020-10-20T17:04:31.676Z - Running post deployment command(s)...  
    2020-10-20T17:04:31.823Z - Triggering recycle (preview mode disabled).  
    2020-10-20T17:04:31.948Z - Deployment successful.  
    

    I did remove pycache and venv and added them to .gitignore as they're not needed for deployments.

    0 comments No comments

  2. Kevin Zhu 26 Reputation points
    2020-10-20T20:21:08.483+00:00

    Hey Ryan,

    Thank you for getting back to me so quickly!

    I just read your response to my two forum posts.
    I can successfully deploy my web page without facing any errors, it's when I get to shnGetCamImg where the page won't load.
    I ran my webpage on my local computer again to see if I faced any of the errors you mentioned but none of them appear.

    Can you try running my webpage after you successfully load it, and fill out the test inputs like so.
    33801-image.png

    After it renders, you should see a page like this that pops up: (excuse the title, didn't add a viewport)
    33811-image.png
    My problem is when I try to load the second page from the azurewebsite, the first page loads perfectly:
    33821-image.png

    but my second page shows this:
    ![33832-image.png]4

    and when I go and diagnose this problem I now get a different error from the Azure portal.
    33841-image.png
    Although I get a different error from the Azure portal, I don't think the pr​oblem I had before in my Azure portal logs:
    33833-image.png
    has been resolved yet.

    I apologize for this being very long, but I wanted to be clear with what I was having trouble with. I can successfully deploy my webpage, but I can't run the second page of my website.
    Please let me know if you have any solution to this and I hope to hear from you soon.