Python 导入错误:没有名为 jinja2 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18944345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:21:16  来源:igfitidea点击:

ImportError: No module named jinja2

pythongoogle-app-enginepython-2.7

提问by Cyril

Using google-app-engine tutorial, I got the following error stack message:

使用 google-app-engine 教程,我收到以下错误堆栈消息:

Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "D:\Dev\SandBoxes\web\omaha\omaha.py", line 4, in <module>
import jinja2
ImportError: No module named jinja2

Even though I declared it in the libraries from app.yaml:

即使我在 app.yaml 的库中声明了它:

application: ***
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: jinja2
  version: latest
- name: webapp2
  version: latest


handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /img
  static_dir: img
- url: /.*
  script: omaha.application

Has anyone had a similar problem?

有没有人遇到过类似的问题?

采纳答案by Cyril

Need to restart application in AEL.

需要在 AEL 中重新启动应用程序。

The application in Google App Engine Launcher must be restarted for new library calls to be taken into account. I was mislead by the fact all other changes dont need actual restart of the server.

必须重新启动 Google App Engine Launcher 中的应用程序才能考虑新的库调用。我被所有其他更改不需要实际重新启动服务器这一事实误导了。

回答by Jesse

Even though it's declared in your libraries it doesn't necessarily mean the dev app server can find the library within the appengine sdk.

即使它在您的库中声明,也不一定意味着开发应用服务器可以在 appengine sdk 中找到该库。

Since you're running the tutorial, I'm assuming you are running the application from googles app engine launcher. Within the laucher go into "Edit" >> "Prefences" and set your Python Path and SDK Path.

由于您正在运行本教程,因此我假设您正在从 googles 应用引擎启动器运行应用程序。在 laucher 中进入“Edit”>>“Prefences”并设置您的 Python 路径和 SDK 路径。

enter image description here

在此处输入图片说明

回答by topless

In order to use Jinja locally, you need to install it locally

为了在本地使用Jinja,需要在本地安装

easy_install Jinja2

or

或者

pip install Jinja2

回答by Kees Briggs

You may not have added the following lines to app.yaml:

您可能没有在 app.yaml 中添加以下几行:

- name: jinja2
  version: latest

回答by user3546879

Use these commands to get pip and Jija2 installed for Python 3:

使用这些命令为 Python 3 安装 pip 和 Jija2:

sudo apt-get install python3-pip
sudo pip3 install Jinja2