ImportError:没有名为flask_restful的模块

时间:2018-07-06 15:45:06

标签: python google-app-engine google-app-engine-python app-engine-flexible

我正在尝试部署appengine flex python应用程序,但部署后在Stackdriver log stderr中得到以下内容

  File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/home/vmagent/app/my_service/entry_point.py", line 5, in <module>
    import flask_restful as restful
ImportError: No module named flask_restful
第5行中的

entry_point.py具有

import flask_restful as restful

我的require.txt有

Flask-RESTful==0.3.6
gunicorn==19.7.1

不确定为什么它仍然抱怨Flask-Restful

4 个答案:

答案 0 :(得分:5)

导入是在某些平台上case sensitive的,即Linux(Windows和Mac可能或可能不关心大小写)。包Flask-RESTful并不像大多数包一样都是小写的(按照PEP 8的建议),因此,import flask_restful as restful会产生导入错误,除非使用适当的大小写。

答案 1 :(得分:1)

  

ImportError:没有名为flask_restful的模块

似乎没有安装 flask_restful 来安装运行:

pip install flask-restful

在您的终端中,然后运行您的应用。

文档:https://flask-restful.readthedocs.io/en/latest/installation.html

答案 2 :(得分:1)

我遇到了同样的问题...我正在使用Visual Studio Code的“播放”按钮运行应用程序,并被卡住。一切都已经安装好了... 一段时间后,我意识到必须使用IDE的控制台并从那里启动程序:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    setHasOptionsMenu(true);

    View view = inflater.inflate(R.layout.fragment_cgpa_frag, container, false);
    recyclerview = (RecyclerView) view.findViewById(R.id.rc2);
    cgpaArrayList = new ArrayList<>();
    //put this method here
    Fetchdata2();
    ac = new adapter_cgpa(cgpaArrayList);
    recyclerview.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
    recyclerview.setAdapter(ac);



    return view;
}

private void Fetchdata2() {
    dbmanager db = new dbmanager(getContext());

    Cursor cursor = db.fetch_data2();

    if (cursor != null) {

        // cursor.moveToFirst();
        while (cursor.moveToNext()) {

            POJO pj = new POJO();
            pj.setCname(cursor.getString(0));
            pj.setNo_of_sems(cursor.getString(1));
            pj.setCgpa(cursor.getString(2));
            pj.setPercentage(cursor.getString(3));
            pj.setSchemec(cursor.getString(4));
            cgpaArrayList.add(pj);
        }

    }

}

我在虚拟环境

下运行它

答案 3 :(得分:0)

  1. 基本上,您的项目根目录与python不匹配 此特定(flask_restful)软件包的根目录,

  2. 卸载python应用程序并将其重新安装在窗口程序文件中,您 应该在您的Windows程序中单独安装python

    我通过此过程(满意的编码)解决了

相关问题