Impossible to import flask_cors with apache2, mod_wsgi under Python3.5 on a Raspberry pi











up vote
1
down vote

favorite












I try to setup a website based on Flask on a Raspberry Pi 3B+, with Apache2 (2.4.25), and mod_wsgi, but I am unable to import the module flask_cors in Python3.5...



I installed mod_wsgi with the command ssudo apt-get install libapache2-mod-wsgi



Because I only plan on using the Raspberry for hosting my website, I tried to install the packages needed by Flask system-wide, with the version 3.5 of Python, with the following command: pip3 install -r requirements.txt where requirements.txt is the following:



click==6.7
Flask==0.12.3
Flask-Cors==3.0.3
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
six==1.11.0
Werkzeug==0.12.2
Requests==2.20.0


I think I understood that on a Raspi, it is best to import the modules wit the command pip3 install -U <module> because the packages are not installed on the default location for python, which is confirmed in my case by the following command python -m site that yields the following information:



sys.path = [
'/home/pi/.local/lib/python3.5/site-packages',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-arm-linux-gnueabihf',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/pi/.local' (exists)
USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (exists)
ENABLE_USER_SITE: True


My Flask and dependencies are indeed installed in the /home/pi/.local/lib/python3.5/site-packages folder. But this does not seem to be a problem because when checking for importing on a python shell, everything seems fine systemwide:



pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask_cors import CORS
>>>


Knowing that, I tried to put the following files to setup my apache server:



flaskregul.conf in the folder /etc/apache2/sites-enabled:



<VirtualHost *:80>
WSGIScriptAlias / /var/www/flaskregul/flaskregul.wsgi
Alias /static/ /var/www/flaskregul/dist/static/
<Directory /var/www/flaskregul/dist/static>
WSGIProcessGroup flaskregul
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/flask.monnomdedomaine.com.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


flaskregul.wsgi in /var/www/flaskregul:



import sys
sys.path.insert(0,"/var/www/flaskregul") # path to my __init__.py file
sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages") # path to the site-packages folder where the modules are installed by pip3
from __init__ import app as application


__init__.py in /var/www/flaskregul:



from flask import Flask
from flask_cors import CORS


I encounter an impossibilty to specifically import the flask_cors module, because the launching of the file __init__.py yields the following errors in the file /var/log/apache2/flask.monnomdedomaine.com.log:



[Sat Nov 10 00:37:22.220394 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Target WSGI script '/var/www/flaskregul/flaskregul.wsgi' cannot be loaded as Python module.
[Sat Nov 10 00:37:22.220972 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Exception occurred processing WSGI script '/var/www/flaskregul/flaskregul.wsgi'.
[Sat Nov 10 00:37:22.221936 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] Traceback (most recent call last):
[Sat Nov 10 00:37:22.222365 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/flaskregul.wsgi", line 1, in <module>
[Sat Nov 10 00:37:22.222395 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from __init__ import app as application
[Sat Nov 10 00:37:22.222445 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/__init__.py", line 2, in <module>
[Sat Nov 10 00:37:22.222463 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from flask_cors import CORS
[Sat Nov 10 00:37:22.222557 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] ImportError: No module named 'flask_cors'


Whereas the import of Flask seems fine...



I've tried to debug this by changing the WSGI script file by this one:



import sys
sys.path.insert(0,"/var/www/flaskregul")
sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages")

def application(environ, start_response):
status = '200 OK'

output = u''
output += u'sys.version = %sn' % repr(sys.version)
output += u'sys.prefix = %sn' % repr(sys.prefix)
output += u'sys.path = %sn' % repr(sys.path)

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output.encode('UTF-8')]


This is a piece of advice the advice on this web page from mod_wsgi: https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html. When opening the webpage, I obtain this result:



sys.version = '3.5.3 (default, Sep 27 2018, 17:25:39) n[GCC 6.3.0 20170516]'
sys.prefix = '/usr'
sys.path = ['/home/pi/.local/lib/python3.5/site-packages', '/var/www/flaskregul', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg', '/usr/lib/python3/dist-packages']


I have the impression that the path is correct! I actually succeed in importing my own modules located in the /var/www/flaskregul location...



I am lost, I don't understand why specifically the module flask_cors is unavaiblable, because it is indeed in the path:



pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l | grep flask
drwxr-xr-x 5 pi pi 4096 nov. 9 23:30 flask
drwxr-xr-x 3 pi pi 4096 nov. 10 00:08 flask_cors
pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l flask_cors
total 44
-rw-r--r-- 1 pi pi 13771 nov. 10 00:08 core.py
-rw-r--r-- 1 pi pi 4937 nov. 10 00:08 decorator.py
-rw-r--r-- 1 pi pi 7405 nov. 10 00:08 extension.py
-rw-r--r-- 1 pi pi 924 nov. 10 00:08 __init__.py
drwxr-xr-x 2 pi pi 4096 nov. 10 00:08 __pycache__
-rw-r--r-- 1 pi pi 22 nov. 10 00:08 version.py


Any help would be very much appreciated! I am currently losing my hair at a worriyng rate!










share|improve this question


























    up vote
    1
    down vote

    favorite












    I try to setup a website based on Flask on a Raspberry Pi 3B+, with Apache2 (2.4.25), and mod_wsgi, but I am unable to import the module flask_cors in Python3.5...



    I installed mod_wsgi with the command ssudo apt-get install libapache2-mod-wsgi



    Because I only plan on using the Raspberry for hosting my website, I tried to install the packages needed by Flask system-wide, with the version 3.5 of Python, with the following command: pip3 install -r requirements.txt where requirements.txt is the following:



    click==6.7
    Flask==0.12.3
    Flask-Cors==3.0.3
    itsdangerous==0.24
    Jinja2==2.9.6
    MarkupSafe==1.0
    six==1.11.0
    Werkzeug==0.12.2
    Requests==2.20.0


    I think I understood that on a Raspi, it is best to import the modules wit the command pip3 install -U <module> because the packages are not installed on the default location for python, which is confirmed in my case by the following command python -m site that yields the following information:



    sys.path = [
    '/home/pi/.local/lib/python3.5/site-packages',
    '/usr/lib/python35.zip',
    '/usr/lib/python3.5',
    '/usr/lib/python3.5/plat-arm-linux-gnueabihf',
    '/usr/lib/python3.5/lib-dynload',
    '/usr/local/lib/python3.5/dist-packages',
    '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg',
    '/usr/lib/python3/dist-packages',
    ]
    USER_BASE: '/home/pi/.local' (exists)
    USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (exists)
    ENABLE_USER_SITE: True


    My Flask and dependencies are indeed installed in the /home/pi/.local/lib/python3.5/site-packages folder. But this does not seem to be a problem because when checking for importing on a python shell, everything seems fine systemwide:



    pi@raspberrypi:~ $ python3
    Python 3.5.3 (default, Sep 27 2018, 17:25:39)
    [GCC 6.3.0 20170516] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from flask_cors import CORS
    >>>


    Knowing that, I tried to put the following files to setup my apache server:



    flaskregul.conf in the folder /etc/apache2/sites-enabled:



    <VirtualHost *:80>
    WSGIScriptAlias / /var/www/flaskregul/flaskregul.wsgi
    Alias /static/ /var/www/flaskregul/dist/static/
    <Directory /var/www/flaskregul/dist/static>
    WSGIProcessGroup flaskregul
    WSGIApplicationGroup %{GLOBAL}
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog /var/log/apache2/flask.monnomdedomaine.com.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>


    flaskregul.wsgi in /var/www/flaskregul:



    import sys
    sys.path.insert(0,"/var/www/flaskregul") # path to my __init__.py file
    sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages") # path to the site-packages folder where the modules are installed by pip3
    from __init__ import app as application


    __init__.py in /var/www/flaskregul:



    from flask import Flask
    from flask_cors import CORS


    I encounter an impossibilty to specifically import the flask_cors module, because the launching of the file __init__.py yields the following errors in the file /var/log/apache2/flask.monnomdedomaine.com.log:



    [Sat Nov 10 00:37:22.220394 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Target WSGI script '/var/www/flaskregul/flaskregul.wsgi' cannot be loaded as Python module.
    [Sat Nov 10 00:37:22.220972 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Exception occurred processing WSGI script '/var/www/flaskregul/flaskregul.wsgi'.
    [Sat Nov 10 00:37:22.221936 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] Traceback (most recent call last):
    [Sat Nov 10 00:37:22.222365 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/flaskregul.wsgi", line 1, in <module>
    [Sat Nov 10 00:37:22.222395 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from __init__ import app as application
    [Sat Nov 10 00:37:22.222445 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/__init__.py", line 2, in <module>
    [Sat Nov 10 00:37:22.222463 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from flask_cors import CORS
    [Sat Nov 10 00:37:22.222557 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] ImportError: No module named 'flask_cors'


    Whereas the import of Flask seems fine...



    I've tried to debug this by changing the WSGI script file by this one:



    import sys
    sys.path.insert(0,"/var/www/flaskregul")
    sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages")

    def application(environ, start_response):
    status = '200 OK'

    output = u''
    output += u'sys.version = %sn' % repr(sys.version)
    output += u'sys.prefix = %sn' % repr(sys.prefix)
    output += u'sys.path = %sn' % repr(sys.path)

    response_headers = [('Content-type', 'text/plain'),
    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output.encode('UTF-8')]


    This is a piece of advice the advice on this web page from mod_wsgi: https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html. When opening the webpage, I obtain this result:



    sys.version = '3.5.3 (default, Sep 27 2018, 17:25:39) n[GCC 6.3.0 20170516]'
    sys.prefix = '/usr'
    sys.path = ['/home/pi/.local/lib/python3.5/site-packages', '/var/www/flaskregul', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg', '/usr/lib/python3/dist-packages']


    I have the impression that the path is correct! I actually succeed in importing my own modules located in the /var/www/flaskregul location...



    I am lost, I don't understand why specifically the module flask_cors is unavaiblable, because it is indeed in the path:



    pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l | grep flask
    drwxr-xr-x 5 pi pi 4096 nov. 9 23:30 flask
    drwxr-xr-x 3 pi pi 4096 nov. 10 00:08 flask_cors
    pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l flask_cors
    total 44
    -rw-r--r-- 1 pi pi 13771 nov. 10 00:08 core.py
    -rw-r--r-- 1 pi pi 4937 nov. 10 00:08 decorator.py
    -rw-r--r-- 1 pi pi 7405 nov. 10 00:08 extension.py
    -rw-r--r-- 1 pi pi 924 nov. 10 00:08 __init__.py
    drwxr-xr-x 2 pi pi 4096 nov. 10 00:08 __pycache__
    -rw-r--r-- 1 pi pi 22 nov. 10 00:08 version.py


    Any help would be very much appreciated! I am currently losing my hair at a worriyng rate!










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I try to setup a website based on Flask on a Raspberry Pi 3B+, with Apache2 (2.4.25), and mod_wsgi, but I am unable to import the module flask_cors in Python3.5...



      I installed mod_wsgi with the command ssudo apt-get install libapache2-mod-wsgi



      Because I only plan on using the Raspberry for hosting my website, I tried to install the packages needed by Flask system-wide, with the version 3.5 of Python, with the following command: pip3 install -r requirements.txt where requirements.txt is the following:



      click==6.7
      Flask==0.12.3
      Flask-Cors==3.0.3
      itsdangerous==0.24
      Jinja2==2.9.6
      MarkupSafe==1.0
      six==1.11.0
      Werkzeug==0.12.2
      Requests==2.20.0


      I think I understood that on a Raspi, it is best to import the modules wit the command pip3 install -U <module> because the packages are not installed on the default location for python, which is confirmed in my case by the following command python -m site that yields the following information:



      sys.path = [
      '/home/pi/.local/lib/python3.5/site-packages',
      '/usr/lib/python35.zip',
      '/usr/lib/python3.5',
      '/usr/lib/python3.5/plat-arm-linux-gnueabihf',
      '/usr/lib/python3.5/lib-dynload',
      '/usr/local/lib/python3.5/dist-packages',
      '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg',
      '/usr/lib/python3/dist-packages',
      ]
      USER_BASE: '/home/pi/.local' (exists)
      USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (exists)
      ENABLE_USER_SITE: True


      My Flask and dependencies are indeed installed in the /home/pi/.local/lib/python3.5/site-packages folder. But this does not seem to be a problem because when checking for importing on a python shell, everything seems fine systemwide:



      pi@raspberrypi:~ $ python3
      Python 3.5.3 (default, Sep 27 2018, 17:25:39)
      [GCC 6.3.0 20170516] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from flask_cors import CORS
      >>>


      Knowing that, I tried to put the following files to setup my apache server:



      flaskregul.conf in the folder /etc/apache2/sites-enabled:



      <VirtualHost *:80>
      WSGIScriptAlias / /var/www/flaskregul/flaskregul.wsgi
      Alias /static/ /var/www/flaskregul/dist/static/
      <Directory /var/www/flaskregul/dist/static>
      WSGIProcessGroup flaskregul
      WSGIApplicationGroup %{GLOBAL}
      Order allow,deny
      Allow from all
      </Directory>
      ErrorLog /var/log/apache2/flask.monnomdedomaine.com.log
      LogLevel warn
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>


      flaskregul.wsgi in /var/www/flaskregul:



      import sys
      sys.path.insert(0,"/var/www/flaskregul") # path to my __init__.py file
      sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages") # path to the site-packages folder where the modules are installed by pip3
      from __init__ import app as application


      __init__.py in /var/www/flaskregul:



      from flask import Flask
      from flask_cors import CORS


      I encounter an impossibilty to specifically import the flask_cors module, because the launching of the file __init__.py yields the following errors in the file /var/log/apache2/flask.monnomdedomaine.com.log:



      [Sat Nov 10 00:37:22.220394 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Target WSGI script '/var/www/flaskregul/flaskregul.wsgi' cannot be loaded as Python module.
      [Sat Nov 10 00:37:22.220972 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Exception occurred processing WSGI script '/var/www/flaskregul/flaskregul.wsgi'.
      [Sat Nov 10 00:37:22.221936 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] Traceback (most recent call last):
      [Sat Nov 10 00:37:22.222365 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/flaskregul.wsgi", line 1, in <module>
      [Sat Nov 10 00:37:22.222395 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from __init__ import app as application
      [Sat Nov 10 00:37:22.222445 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/__init__.py", line 2, in <module>
      [Sat Nov 10 00:37:22.222463 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from flask_cors import CORS
      [Sat Nov 10 00:37:22.222557 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] ImportError: No module named 'flask_cors'


      Whereas the import of Flask seems fine...



      I've tried to debug this by changing the WSGI script file by this one:



      import sys
      sys.path.insert(0,"/var/www/flaskregul")
      sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages")

      def application(environ, start_response):
      status = '200 OK'

      output = u''
      output += u'sys.version = %sn' % repr(sys.version)
      output += u'sys.prefix = %sn' % repr(sys.prefix)
      output += u'sys.path = %sn' % repr(sys.path)

      response_headers = [('Content-type', 'text/plain'),
      ('Content-Length', str(len(output)))]
      start_response(status, response_headers)

      return [output.encode('UTF-8')]


      This is a piece of advice the advice on this web page from mod_wsgi: https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html. When opening the webpage, I obtain this result:



      sys.version = '3.5.3 (default, Sep 27 2018, 17:25:39) n[GCC 6.3.0 20170516]'
      sys.prefix = '/usr'
      sys.path = ['/home/pi/.local/lib/python3.5/site-packages', '/var/www/flaskregul', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg', '/usr/lib/python3/dist-packages']


      I have the impression that the path is correct! I actually succeed in importing my own modules located in the /var/www/flaskregul location...



      I am lost, I don't understand why specifically the module flask_cors is unavaiblable, because it is indeed in the path:



      pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l | grep flask
      drwxr-xr-x 5 pi pi 4096 nov. 9 23:30 flask
      drwxr-xr-x 3 pi pi 4096 nov. 10 00:08 flask_cors
      pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l flask_cors
      total 44
      -rw-r--r-- 1 pi pi 13771 nov. 10 00:08 core.py
      -rw-r--r-- 1 pi pi 4937 nov. 10 00:08 decorator.py
      -rw-r--r-- 1 pi pi 7405 nov. 10 00:08 extension.py
      -rw-r--r-- 1 pi pi 924 nov. 10 00:08 __init__.py
      drwxr-xr-x 2 pi pi 4096 nov. 10 00:08 __pycache__
      -rw-r--r-- 1 pi pi 22 nov. 10 00:08 version.py


      Any help would be very much appreciated! I am currently losing my hair at a worriyng rate!










      share|improve this question













      I try to setup a website based on Flask on a Raspberry Pi 3B+, with Apache2 (2.4.25), and mod_wsgi, but I am unable to import the module flask_cors in Python3.5...



      I installed mod_wsgi with the command ssudo apt-get install libapache2-mod-wsgi



      Because I only plan on using the Raspberry for hosting my website, I tried to install the packages needed by Flask system-wide, with the version 3.5 of Python, with the following command: pip3 install -r requirements.txt where requirements.txt is the following:



      click==6.7
      Flask==0.12.3
      Flask-Cors==3.0.3
      itsdangerous==0.24
      Jinja2==2.9.6
      MarkupSafe==1.0
      six==1.11.0
      Werkzeug==0.12.2
      Requests==2.20.0


      I think I understood that on a Raspi, it is best to import the modules wit the command pip3 install -U <module> because the packages are not installed on the default location for python, which is confirmed in my case by the following command python -m site that yields the following information:



      sys.path = [
      '/home/pi/.local/lib/python3.5/site-packages',
      '/usr/lib/python35.zip',
      '/usr/lib/python3.5',
      '/usr/lib/python3.5/plat-arm-linux-gnueabihf',
      '/usr/lib/python3.5/lib-dynload',
      '/usr/local/lib/python3.5/dist-packages',
      '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg',
      '/usr/lib/python3/dist-packages',
      ]
      USER_BASE: '/home/pi/.local' (exists)
      USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (exists)
      ENABLE_USER_SITE: True


      My Flask and dependencies are indeed installed in the /home/pi/.local/lib/python3.5/site-packages folder. But this does not seem to be a problem because when checking for importing on a python shell, everything seems fine systemwide:



      pi@raspberrypi:~ $ python3
      Python 3.5.3 (default, Sep 27 2018, 17:25:39)
      [GCC 6.3.0 20170516] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from flask_cors import CORS
      >>>


      Knowing that, I tried to put the following files to setup my apache server:



      flaskregul.conf in the folder /etc/apache2/sites-enabled:



      <VirtualHost *:80>
      WSGIScriptAlias / /var/www/flaskregul/flaskregul.wsgi
      Alias /static/ /var/www/flaskregul/dist/static/
      <Directory /var/www/flaskregul/dist/static>
      WSGIProcessGroup flaskregul
      WSGIApplicationGroup %{GLOBAL}
      Order allow,deny
      Allow from all
      </Directory>
      ErrorLog /var/log/apache2/flask.monnomdedomaine.com.log
      LogLevel warn
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>


      flaskregul.wsgi in /var/www/flaskregul:



      import sys
      sys.path.insert(0,"/var/www/flaskregul") # path to my __init__.py file
      sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages") # path to the site-packages folder where the modules are installed by pip3
      from __init__ import app as application


      __init__.py in /var/www/flaskregul:



      from flask import Flask
      from flask_cors import CORS


      I encounter an impossibilty to specifically import the flask_cors module, because the launching of the file __init__.py yields the following errors in the file /var/log/apache2/flask.monnomdedomaine.com.log:



      [Sat Nov 10 00:37:22.220394 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Target WSGI script '/var/www/flaskregul/flaskregul.wsgi' cannot be loaded as Python module.
      [Sat Nov 10 00:37:22.220972 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Exception occurred processing WSGI script '/var/www/flaskregul/flaskregul.wsgi'.
      [Sat Nov 10 00:37:22.221936 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] Traceback (most recent call last):
      [Sat Nov 10 00:37:22.222365 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/flaskregul.wsgi", line 1, in <module>
      [Sat Nov 10 00:37:22.222395 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from __init__ import app as application
      [Sat Nov 10 00:37:22.222445 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/__init__.py", line 2, in <module>
      [Sat Nov 10 00:37:22.222463 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from flask_cors import CORS
      [Sat Nov 10 00:37:22.222557 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] ImportError: No module named 'flask_cors'


      Whereas the import of Flask seems fine...



      I've tried to debug this by changing the WSGI script file by this one:



      import sys
      sys.path.insert(0,"/var/www/flaskregul")
      sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages")

      def application(environ, start_response):
      status = '200 OK'

      output = u''
      output += u'sys.version = %sn' % repr(sys.version)
      output += u'sys.prefix = %sn' % repr(sys.prefix)
      output += u'sys.path = %sn' % repr(sys.path)

      response_headers = [('Content-type', 'text/plain'),
      ('Content-Length', str(len(output)))]
      start_response(status, response_headers)

      return [output.encode('UTF-8')]


      This is a piece of advice the advice on this web page from mod_wsgi: https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html. When opening the webpage, I obtain this result:



      sys.version = '3.5.3 (default, Sep 27 2018, 17:25:39) n[GCC 6.3.0 20170516]'
      sys.prefix = '/usr'
      sys.path = ['/home/pi/.local/lib/python3.5/site-packages', '/var/www/flaskregul', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg', '/usr/lib/python3/dist-packages']


      I have the impression that the path is correct! I actually succeed in importing my own modules located in the /var/www/flaskregul location...



      I am lost, I don't understand why specifically the module flask_cors is unavaiblable, because it is indeed in the path:



      pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l | grep flask
      drwxr-xr-x 5 pi pi 4096 nov. 9 23:30 flask
      drwxr-xr-x 3 pi pi 4096 nov. 10 00:08 flask_cors
      pi@raspberrypi:~/.local/lib/python3.5/site-packages $ l flask_cors
      total 44
      -rw-r--r-- 1 pi pi 13771 nov. 10 00:08 core.py
      -rw-r--r-- 1 pi pi 4937 nov. 10 00:08 decorator.py
      -rw-r--r-- 1 pi pi 7405 nov. 10 00:08 extension.py
      -rw-r--r-- 1 pi pi 924 nov. 10 00:08 __init__.py
      drwxr-xr-x 2 pi pi 4096 nov. 10 00:08 __pycache__
      -rw-r--r-- 1 pi pi 22 nov. 10 00:08 version.py


      Any help would be very much appreciated! I am currently losing my hair at a worriyng rate!







      apache flask pip raspberry-pi3 wsgi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 0:04









      Skyline124

      63




      63
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Oh my god I solved it in a desperate try before giving up.



          I executed the following commands on a shell: (pip is the pip of the python3.5 /!)



          pip uninstall flask
          pip uninstall flask_cors
          sudo pip install --upgrade pip
          hash -d pip
          sudo pip install -U flask
          sudo pip install -U flask_cors


          Website up and running! :D






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234827%2fimpossible-to-import-flask-cors-with-apache2-mod-wsgi-under-python3-5-on-a-rasp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            Oh my god I solved it in a desperate try before giving up.



            I executed the following commands on a shell: (pip is the pip of the python3.5 /!)



            pip uninstall flask
            pip uninstall flask_cors
            sudo pip install --upgrade pip
            hash -d pip
            sudo pip install -U flask
            sudo pip install -U flask_cors


            Website up and running! :D






            share|improve this answer

























              up vote
              0
              down vote



              accepted










              Oh my god I solved it in a desperate try before giving up.



              I executed the following commands on a shell: (pip is the pip of the python3.5 /!)



              pip uninstall flask
              pip uninstall flask_cors
              sudo pip install --upgrade pip
              hash -d pip
              sudo pip install -U flask
              sudo pip install -U flask_cors


              Website up and running! :D






              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Oh my god I solved it in a desperate try before giving up.



                I executed the following commands on a shell: (pip is the pip of the python3.5 /!)



                pip uninstall flask
                pip uninstall flask_cors
                sudo pip install --upgrade pip
                hash -d pip
                sudo pip install -U flask
                sudo pip install -U flask_cors


                Website up and running! :D






                share|improve this answer












                Oh my god I solved it in a desperate try before giving up.



                I executed the following commands on a shell: (pip is the pip of the python3.5 /!)



                pip uninstall flask
                pip uninstall flask_cors
                sudo pip install --upgrade pip
                hash -d pip
                sudo pip install -U flask
                sudo pip install -U flask_cors


                Website up and running! :D







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 0:27









                Skyline124

                63




                63






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234827%2fimpossible-to-import-flask-cors-with-apache2-mod-wsgi-under-python3-5-on-a-rasp%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff