I wrote a simple background with the flask framework, the project is written by pycharm, the virtual environment is automatically configured by pycharm when developing, and the project directory is as follows.
-
app
- _ _ init__.py
-
match
- _ _ init__.py
- views.py
-
user
- _ _ init__.py
- views.py
- static
- venv
- config.py
- manage.py
match and user are two blueprints, and app runs in the top-level manage.py.
there is no problem with the development. Pycharm can debug normally, but there is a problem when preparing to deploy to the server.
is deployed in the way of Nginx + uWSGI. After I download the directory to the server with git, I create a new virtual environment
pip install -r requirtment.txt
installation depends on the environment. The contents of the file are as follows:
aniso8601==3.0.0
certifi==2018.4.16
chardet==3.0.4
click==6.7
crcmod==1.7
Flask==0.12.2
Flask-RESTful==0.3.6
Flask-SQLAlchemy==2.3.2
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
oss2==2.4.0
PyMySQL==0.8.0
pytz==2018.4
requests==2.18.4
six==1.11.0
SQLAlchemy==1.2.6
urllib3==1.22
Werkzeug==0.14.1
the new configuration file for pip installation uwsgi, after installation is as follows:
[uwsgi]
socket = 127.0.0.1:8000
-sharp
chdir = /data/Dudu/
plugins=python34
home = /data/Dudu/env/
vhost = true
no-site=true
-sharp flask
wsgi-file =manage.py
-sharp flaskmanage.pyapp
callable = app
-sharp
processes = 1
-sharp
threads = 2
-sharp
uid = root
gid = root
nginx is previously configured and can jump 502.
error running uwsgi,
pythonpath=/data/Dudu/env/lib/python3.4/site-packages
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "manage.py", line 1, in <module>
from app import app_create
File "./app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named "flask"
unable to load app 0 (mountpoint="") (callable not found or import error)
various queries, add a setting:
added / data/Dudu/env/lib/python3.4/site-packages/ to pythonpath.
still report an error:
added /data/Dudu/env/bin/python3 to pythonpath.
Traceback (most recent call last):
File "manage.py", line 1, in <module>
from app import app_create
File "./app/__init__.py", line 1, in <module>
from flask import Flask
File "/data/Dudu/env/lib/python3.4/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/data/Dudu/env/lib/python3.4/site-packages/werkzeug/__init__.py", line 151, in <module>
__import__("werkzeug.exceptions")
File "/data/Dudu/env/lib/python3.4/site-packages/werkzeug/exceptions.py", line 67, in <module>
from werkzeug._internal import _get_environ
File "/data/Dudu/env/lib/python3.4/site-packages/werkzeug/_internal.py", line 12, in <module>
import string
ImportError: No module named "string"
unable to load app 0 (mountpoint="") (callable not found or import error)
I have seen the answers to almost all the related questions in the past two days, and all kinds of packages in the virtual environment have also been installed and installed, but they are still unsolved. The server is a centos,python3.4/2.7 environment, before running a flask project, can run normally, now just can not find the flask module, really fascinated. I hope you can give us your advice.
manage.py:
from app import app_create
app=app_create()
if __name__ == "__main__":
app.run(port = 8000)
~
app/__init__.py
from flask import Flask
import config
from .models import db
def app_create():
from .match import match as match_blueprint
from .user import user as user_blueprint
app = Flask(__name__)
app.config.from_object(config)
app.secret_key="1234"
db.init_app(app)
app.register_blueprint(match_blueprint)
app.register_blueprint(user_blueprint)
return app
~
Boss, help rookies, thank you very much