无法导入已存在的模块
我在命令行中无法导入appengine,这可能跟我的Python路径有关:
$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext import db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "google/appengine/ext/db/__init__.py", line 98, in <module>
from google.appengine.api import datastore
File "google/appengine/api/datastore.py", line 62, in <module>
from google.appengine.datastore import datastore_query
File "google/appengine/datastore/datastore_query.py", line 64, in <module>
from google.appengine.datastore import datastore_index
File "google/appengine/datastore/datastore_index.py", line 60, in <module>
from google.appengine.api import validation
File "google/appengine/api/validation.py", line 51, in <module>
import yaml
ImportError: No module named yaml
>>>
我不想有重复的安装,我想让Python解释器知道缺失的模块在哪里。我该怎么做才能让解释器在命令提示符下找到app engine模块?在我的应用程序中,这些导入是可以正常工作的。
3 个回答
6
你的当前环境中没有安装yaml。yaml这个包是和google_appengine一起放在lib文件夹里的。文件夹中的setup.py脚本会把yaml包添加到你现在的python环境中。
cd google_appengine/lib/yaml
sudo python setup.py install
8
对于 appengine 1.9.6,谷歌创建了一个新的文件夹 "yaml-3.10",里面包含了 yaml 模块。我把 "[appengine 安装目录]/google_appengine/lib/yaml-3.10" 加入到了我的 .bashrc 文件中的 PYTHONPATH 里,这样就解决了这个问题。顺便说一下,我使用的是 Ubuntu 14.04 LTS。
14
添加:
/usr/local/google_appengine/:/usr/local/google_appengine/lib/:/usr/local/google_appengine/lib/yaml/
把它加到你的 PYTHONPATH 环境变量里就可以了(你的 SDK 位置可能会有所不同)。