1

I am trying to deploy a flask app on a VPS using WSGI. I am not using a virtualenv, and pandas is installed on the system:

Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> print 'Works!'
Works!

Still I get this error:

[Sat Jun 01 16:02:52.876184 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860] mod_wsgi (pid=24086): Target WSGI script '/var/www/im/server.wsgi' cannot be loaded as Python module.
[Sat Jun 01 16:02:52.876217 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860] mod_wsgi (pid=24086): Exception occurred processing WSGI script '/var/www/im/server.wsgi'.
[Sat Jun 01 16:02:52.876236 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860] Traceback (most recent call last):
[Sat Jun 01 16:02:52.876254 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860]   File "/var/www/im/server.wsgi", line 7, in <module>
[Sat Jun 01 16:02:52.876278 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860]     from UI import app as application
[Sat Jun 01 16:02:52.876286 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860]   File "/var/www/im/UI/__init__.py", line 3, in <module>
[Sat Jun 01 16:02:52.876297 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860]     import pandas as pd
[Sat Jun 01 16:02:52.876315 2019] [wsgi:error] [pid 24086] [client 27.7.8.82:59860] ImportError: No module named pandas

Here is the WSGI file:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/im/")

from UI import app as application
application.secret_key = 'Add your secret key'

can someone point out what is wrong? I am trying this on a Ubuntu 18.04.2 LTS.

0

1 Answer 1

1

Most likely you have one more Python interpreter installed on the box. To check that do the following:

  • From server console run python and execute these command:

    import sys
    print sys.path
    
  • Create a test Flask app run.py below, place it into /var/www/im/ folder and edit WSGI file to load it: from run import app as application

    import sys
    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def get_path():
        return str(sys.path)
    
  • compare output from both

1
  • Good advice, I've actually managed to solve my own problem following those steps, Python 3.5 was used by Apache while my CLI resolved python 2.7 Dec 3, 2019 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .