2012-01-09 65 views
14

從命令行中我不能導入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解釋器到缺少模塊的位置。如何讓解釋器從命令提示符找到應用程序引擎模塊?在應用程序中,這些導入工作正常。

回答

14

追加:

/usr/local/google_appengine/:/usr/local/google_appengine/lib/:/usr/local/google_appengine/lib/yaml/ 

你PYTHONPATH環境變量應該做的伎倆(你的SDK位置可能不同)。

+0

有時你添加到您的PYTHONPATH順序可以有所作爲的一些庫可以在錯誤的順序發生衝突。還要檢查你的模塊是否安裝了相同版本的Python。您可能已經爲Python 2.6安裝了它們,並且請注意在Python 2.7中安裝它們。 – 2012-01-09 14:43:23

+4

我必須將yaml更改爲yaml-3.10,因爲@Clyde的回答提到 – dghubble 2014-11-27 11:00:58

8

對於appengine 1.9.6,google已經創建了一個包含yaml模塊的新目錄「yaml-3.10」。我在我的.bashrc文件中添加了「[appengine install directory] ​​/google_appengine/lib/yaml-3.10」到PYTHONPATH,並解決了這個問題。順便說一句:我使用Ubuntu 14.04 LTS。

6

yaml未安裝在您當前的設置中。 yaml包包含在lib文件夾中的google_appengine中。該文件夾中的setup.py腳本將YAML包添加到您當前的Python

cd google_appengine/lib/yaml 
sudo python setup.py install 
+0

這個答案可以通過解釋爲什麼提問者有問題以及如何運行這些命令來解決他們的問題來改進。 – ArtOfWarfare 2014-11-17 15:51:32

+0

是更好的? – semisided1 2014-11-17 19:41:32