I
I
idin2017-10-10 00:30:44
Nginx
idin, 2017-10-10 00:30:44

I'm trying to set up Nginx gunicornb Flask, gunicornb doesn't see Flask on startup. Why?

I have a question, I am learning to configure nginx. Now I'm setting up flask.
While the site structure is

name_site
- app
-- app.py
-- static
--- logo.png

- env

​​installed virtuallenv,
ran installed Flask and
here is the result:

$ sudo pip freeze
click==6.7
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
pycurl==7.43.0
pygobject==3.20.0
python-apt==1.1.0b1
unattended-upgrades==0.1
virtualenv==15.1.0
Werkzeug==0.12.2
The directory '/home/iz/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.


then I exited virtuallenv with the deactivate command ,

and then I set up nginx configs and wrote app.py:

from flask import Flask, jsonify
app = Flask(__name__)
 
@app.route('/')
def index():
    return 'Flask is running!'
 
@app.route('/data')
def names():
    data = {"names": ["John", "Jacob", "Julie", "Jennifer"]}
    return jsonify(data)
 
if __name__ == '__main__':
    app.run()


then I go to the
name_site/app/
folder and run the command gunicorn app:app -b localhost:8000
and it gives me:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 366, in import_app
    __import__(module)
  File "/var/www/itant/app/app.py", line 1, in <module>
    from flask import Flask, jsonify
ImportError: No module named flask
[2017-10-09 17:17:14 +0000] [22142] [INFO] Worker exiting (pid: 22142)
[2017-10-09 17:17:14 +0000] [22137] [INFO] Shutting down: Master
[2017-10-09 17:17:14 +0000] [22137] [INFO] Reason: Worker failed to boot.


And the question is why?
Am I using the rights again, or have I missed something, or am I running it wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
landergate, 2017-10-10
@Izy

Packages installed inside a virtualenv are only available when the virtualenv is activated. Outside of them, by default, no. Running the interpreter outside the virtualenv looks for packages in the global system directories, not in the virtualenv.
gunicorn needs to be installed via pip inside virtualenv and called from virtualenv/bin/
docs.gunicorn.org/en/stable/deploy.html#using-virt...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question