2016-03-18 65 views
0

我正在嘗試使用feed-parser模塊來處理此項目。當我將文件上傳到App Engine並運行該腳本時,它返回了錯誤,即沒有名爲feed-parser的模塊。將Python模塊添加到Google App Engine項目

所以我想知道是否以及如何在App Engine上安裝此模塊,以便我可以修復此錯誤並使用RSS。

錯誤:

Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle 
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler 
    handler, path, err = LoadObject(self._handler) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject 
    obj = __import__(path[0]) 
    File "/base/data/home/apps/s~vlis-mannipulus-bot/1.391465315184045822/main.py", line 7, in <module> 
    import feedparser 
ImportError: No module named feed parser 

  • 發展1:

所以我試着在我創建的lib目錄下安裝模塊(在這個例子失敗我--prefix = ..忘了/ lib。)。我在shell中顯示PYTHONERROR。我已經做了一些python路徑的研究,並且我嘗試的解決方案對我沒有幫助。

kevins-MacBook-Pro-2:~ KevinH$ cd /Users/KevinH/Downloads/feedparser -5.2.1 
kevins-MacBook-Pro-2:feedparser-5.2.1 KevinH$ sudo python setup.py  install --prefix=/Users/KevinH/Documents/Thalia\ VMbot/Thalia-VMbot/ 
Password: 
running install 
Checking .pth file support in /Users/KevinH/Documents/Thalia  VMbot/Thalia-VMbot//lib/python2.7/site-packages/ 
/usr/bin/python -E -c pass 
TEST FAILED: /Users/KevinH/Documents/Thalia VMbot/Thalia- VMbot//lib/python2.7/site-packages/ does NOT support .pth files 
error: bad install directory or PYTHONPATH 

You are attempting to install a package to a directory that is not 
on PYTHONPATH and which Python does not read ".pth" files from. The 
installation directory you specified (via --install-dir, --prefix, or 
the distutils default setting) was: 

/Users/KevinH/Documents/Thalia VMbot/Thalia-VMbot//lib/python2.7/site- packages/ 

and your PYTHONPATH environment variable currently contains: 

'' 

Here are some of your options for correcting the problem: 

* You can choose a different installation directory, i.e., one that is 
on PYTHONPATH or supports .pth files 

* You can add the installation directory to the PYTHONPATH environment 
variable. (It must then also be on PYTHONPATH whenever you run 
Python and want to use the package(s) you are installing.) 

* You can set up the installation directory to support ".pth" files by 
using one of the approaches described here: 

https://pythonhosted.org/setuptools/easy_install.html#custom- installation-locations 

Please make the appropriate changes for your system and try again. 

然後,我嘗試用「點子」的命令,但後來我得到這個:

can't open file 'pip': [Errno 2] No such file or directory 

據我已閱讀「點子」應該是與Python 2.7和最多安裝的默認程序。所以爲了確保我安裝了python3.5並運行它,仍然得到相同的錯誤。我打這個既蟒蛇:

kevins-MacBook-Pro-2:feedparser KevinH$ python3 pip -m install feedparse 

-

不知道這是否會工作,但通過終端我跑到哪裏飼料解析器已經安裝在我的系統默認的目錄,並將其複製到我做的lib目錄。然後,我已經創建了以下配置文件:

from google.appengine.ext import vendor 

# Add any libraries installed in the "lib" folder. 
vendor.add('lib') 

其部署和IM仍然得到同樣的錯誤如上沒有模塊名爲feeedparser。

道歉,如果我做了一些愚蠢的錯誤,我仍然在學習過程中。

解釋如何添加第三方模塊
+0

您應用中的feedparser文件在哪裏?另外,你可以發佈你的appengine_config.py文件的內容,如果你有嗎? – snakecharmerb

+0

@snakecharmerb它不在我的應用程序文件中,它自動在我的系統上安裝模塊。我應該找到一種方法將它安裝在aap根文件中嗎?並且不,我還沒有appengine_config.py文件。正如我的研究,雖然我是你處理模塊的文件? – Kevin

回答

0

的App Engine文檔是here

總之,您將需要添加一個文件夾,通常命名爲「LIB」,到頂級了你的應用程序,然後安裝feedparser使用文檔中描述的命令進入該文件夾。您還需要創建一個appengine_config.py文件,如文檔中所述。

請注意,並非所有第三方軟件包都可以上傳到App Engine--那些帶有C擴展名的軟件包被禁止。 Feedparser雖然看起來不錯。

編輯:進一步的意見基於編輯「發展1」的問題。

您的appengine_config.py看起來不錯。

您的「lib」文件夾應該是您的應用程序文件夾,即與您的app.yamlappengine_config.py文件相同的文件夾。

您需要將feedparser軟件包安裝到lib文件夾中。該谷歌文檔建議您通過運行命令

pip install -t lib feedparser

該命令將feedparser包安裝到您的lib文件夾中做到這一點。

您需要安裝並運行與Python2.x一起使用的pip版本 - Python3版本將創建僅在Python3下運行的feedparser版本。

如果您無法安裝Python2的點數this question可能會提供正確的解決方案,否則我會建議您詢問有關如何將feedparser安裝到Mac上的自定義安裝目錄中的單獨問題。一臺Mac,所以我無法幫助。

將feedparser安裝到lib文件夾後,確認您的應用程序在本地工作;尤其是驗證它是否使用lib/feedparser安裝:導入feedparser後,嘗試記錄feedparser.__file__以檢查正在導入的文件的位置。

一旦所有事情都在本地工作,您應該能夠上傳到GAE。

總之,您的appengine_config.py看起來不錯,但您需要確保在上傳到App Engine之前,將正確版本的feedparser安裝到應用程序文件夾的lib文件夾中。

+0

即時嘗試將它安裝在非默認目錄中時,即時獲取此錯誤: '您正在嘗試將軟件包安裝到PYTHONPATH上不是 的目錄中,以及哪個Python不讀取「.pth」文件。您指定的 安裝目錄(通過--install-dir,--prefix或 distutils默認設置)爲' – Kevin

+0

我已經設法獲取lib目錄中的feed parser.egg文件並添加了appegine配置文件,但是即時通訊仍然得到同樣的錯誤X__X我應該編輯第一個問題與這些發展爲你看? – Kevin

+0

是的,請複製並粘貼您輸入的命令和輸出。 – snakecharmerb

相關問題