2017-04-23 126 views
1

我使用pylintVisual Studio Code開發Google App Engine(GAE)Cloud Endpoint API in Python。我無法解決lint錯誤。我不知道是什麼原因造成的錯誤,但有人猜測,pylint找不到protorpc庫?Visual Studio代碼pylint:無法導入'protorpc'

enter image description here

推薦的修復程序Troubleshooting Linting是配置工作區設置爲指向完全合格的蟒蛇可執行文件。我已經這樣做了,但是lint錯誤仍然存​​在。

enter image description here

protorpc本身安裝到:

~/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0/protorpc 

...這包含了remote.py模塊,無法導入:

__init__.py    generate_python.py  protojson.py   transport.py 
definition.py   google_imports.py  protourlencode.py  util.py 
descriptor.py   message_types.py  registry.py    webapp 
generate.py    messages.py    remote.py    wsgi 
generate_proto.py  protobuf.py    static 

我已經添加了此路徑$PYTHONPATH(連同kitchen sink):

export GOOGLE_CLOUD_SDK=~/google-cloud-sdk 
export APPENGINE_PATH=$GOOGLE_CLOUD_SDK/platform/google_appengine 

export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK 
export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK/lib 
export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK/lib/googlecloudsdk 
export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK/lib/googlecloudsdk/api_lib 
export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK/platform/google_appengine/lib 
export PYTHONPATH=$PYTHONPATH:$GOOGLE_CLOUD_SDK/platform/google_appengine/lib/protorpc-1.0/protorpc 

該應用程序在本地運行,也在部署時運行,因此這看起來只是一個lint錯誤,但令人沮喪的是我無法解決它。

Using third-party libraries狀態:

在標準環境中的Python運行包括了Python 標準庫,App Engine的圖書館,以及一些捆綁 第三方軟件包。

正因爲如此,我認爲 '在App Engine庫' 包括protorpc,但我不能確定。此外,Adding the Cloud Endpoints Frameworks library to the sample API只需要谷歌的端點安裝到應用程序的lib目錄:

pip install -t lib google-endpoints --extra-index-url=https://gapi-pypi.appspot.com/admin/nurpc-dev --ignore-installed 

我想說的是,我不認爲我沒有裝東西,我不認爲我失去了什麼在我的(網絡)應用程序的lib目錄中。

+0

如果Morad的帖子是答案,建議將其標記爲更好地幫助社區的解決方案。如果你已經解決了這個問題,你也可以發佈自己的答案並將其標記爲解決方案。請注意,在App Engine中使用第三方庫時,您必須[供應商](https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library )以正確安裝和使用它們。 – Jordan

回答

2

我加入了ProtoRPC的庫到$PYTHONPATH環境變量解決了這個。具體來說,我指着安裝在我的App Engine的目錄庫:

export PYTHONPATH=$PYTHONPATH:/Users/jackwootton/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0 

加入這~/.bash_profile,重新啓動我的機器和Visual Studio代碼後,導入錯誤就走開了。

爲了完整,我做了而不是修改了任何與Python相關的Visual Studio代碼設置。Full ~/.bash_profile file:

export PATH=/Users/jackwootton/protoc3/bin:$PATH 

export PYTHONPATH=/Users/jackwootton/google-cloud-sdk/platform/google_appengine 

export PYTHONPATH=$PYTHONPATH:/Users/jackwootton/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0 

# The next line updates PATH for the Google Cloud SDK. 
if [ -f '/Users/jackwootton/google-cloud-sdk/path.bash.inc' ]; then source '/Users/jackwootton/google-cloud-sdk/path.bash.inc'; fi 

# The next line enables shell command completion for gcloud. 
if [ -f '/Users/jackwootton/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/jackwootton/google-cloud-sdk/completion.bash.inc'; fi 
0

打開Visual Studio代碼(settings.json)的設置文件,並將庫路徑添加到"python.autoComplete.extraPaths"列表中。

"python.autoComplete.extraPaths": [ 
    "~/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2", 
    "~/google-cloud-sdk/platform/google_appengine", 
    "~/google-cloud-sdk/lib", 
    "~/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0", 
    "~/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0" 
], 
+0

你需要用你的程序文件路徑替換〜還是像這樣很好? –