skip to Main Content

I’m running a flask script using wsgi on an apache web server (Amazon Linux 2).

I’m getting a "ModuleNotFoundError: No module named ‘cv2’" error using Python 3.7.

  • I don’t get this error with other modules, I suspect it’s because cv2 is the only one stored in
    "/home/ec2-user/.local/lib/python3.7/site-packages". Others are in "/usr/local/lib/python3.7/site-packages/"

  • I checked the file permissions for the site-packages folder and the directory didn’t have read writes.
    I added it for all users (the script is run by the apache user, not the owner).

  • I checked that "/home/ec2-user/.local/lib/python3.7/site-packages" is in sys.path

  • Import works correctly when I run the flask script without wgsi

  • It’s not an issue of confusion between python 2 and 3, because importing modules that I only have in python3 is working

  • My mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so file is compatible with python 3.7

  • Since I’m not using daemon mode, I can try to add a WSGIPythonPath /home/ec2-user/.local/lib/python3.7/site-packages/ line to my apache configuration, which not surprisingly did not fix the issue

  • I tried to add sys.path.insert(0, '/home/ec2-user/.local/lib/python3.7/site-packages/') before the cv2 import but it didn’t work

  • I’m not running any kind of virtual environment

conf/httpd-le-ssl.conf

<IfModule mod_ssl.c>

#WSGIPythonPath /home/ec2-user/.local/lib/python3.7/site-packages/

<VirtualHost *:443>
    DocumentRoot "/var/www/html"
    ServerName "domain.app"
    ServerAdmin "[email protected]"
    ServerAlias "www.domain.app"

    WSGIScriptAlias / /var/www/application/myapplication.wsgi

    <Directory /var/www/application>
        Require all granted
    </Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.app/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.app/privkey.pem


</VirtualHost>
</IfModule>

Any help is appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    It turns out both .local and site-packages did not have execute permissions. I thought the read permission allows traversing the directory, but apparently it's the execute permission.

    I just ran chmod a+x directoryName on the two directories and it worked.

    I also had to uncomment the WSGIPythonPath line.


  2. This could be because the module is not in the path(you could be changing the path improperly) or something small like that. Maybe this could be that the module was improperly placed or it was deleted somehow. I am a noob, but I try to help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search