Flask uwsgi配置时,找不到flask模块,virtualenv已配置

冬瓜真瓜
  • 14

我用flask框架写了一个简单的后台,项目是pycharm写的,开发的时候虚拟环境是由pycharm自动配置的,项目目录如下。

  • app

    • __init__.py
    • match

      • __init__.py
      • views.py
    • user

      • __init__.py
      • views.py
  • static
  • venv
  • config.py
  • manage.py

match和user是两个蓝图,app的运行放在最顶级的manage.py当中。
开发的时候没有任何问题,pycharm能够正常的调试,但准备部署到服务器上时出现了问题。
采用Nginx + uWSGI 的方式部署,我用git将目录下载到服务器后,新建虚拟环境

pip install -r requirtment.txt

安装依赖环境。文件内容如下:

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

安装完后pip安装 uwsgi,新建配置文件如下:

[uwsgi]
socket = 127.0.0.1:8000

# 指向项目目录
chdir = /data/Dudu/
plugins=python34

home = /data/Dudu/env/
vhost = true

no-site=true

# flask启动程序文件
wsgi-file =manage.py

# flask在manage.py文件中的app名
callable = app

# 处理器数
processes = 1

# 线程数
threads = 2

#状态检测地址

uid = root
gid = root

nginx是之前配置好的,能够502跳转。
运行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)

各种查询,加了一个设置:
added /data/Dudu/env/lib/python3.4/site-packages/ to pythonpath.
依然报错:



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)

这两天已经看完了几乎所有相关问题的解答,虚拟环境下各种包也是装了又装,依然没有解决。服务器是centos,python3.4/2.7环境,之前运行过一个flask项目,能够正常运行,现在就是找不到flask模块,真的很迷。望各位大佬指教。
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
~

大佬们,帮帮菜鸟,万分感谢啊

回复
阅读 4.6k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏