Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code pylint: Unable to import 'protorpc'

I'm using pylint in Visual Studio Code to develop a Google App Engine (GAE) Cloud Endpoint API in Python. I'm unable to resolve a lint error. I don't know what's causing the error, but at a guess, pylint cannot find the protorpc library?

enter image description here

The recommended fix in Troubleshooting Linting is to configure workspace settings to point to fully qualified python executable. I have done this, but the lint error remains.

enter image description here

protorpc itself is installed to:

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

...and this contains the remote.py module that cannot be imported:

__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 

I've added this path to $PYTHONPATH (along with the 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 

The application runs locally and also when deployed, so this appears to be just a lint error, but it's frustrating that I can't solve it.

Using third-party libraries states:

The Python runtime in the standard environment includes the Python standard library, the App Engine libraries, and a few bundled third-party packages.

Because of this, I assumed 'the App Engine libraries' includes protorpc, but I'm unsure. Moreover, Adding the Cloud Endpoints Frameworks library to the sample API only requires google-endpoints be installed to the app's lib directory:

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

My point is, I don't think I've not installed something, and I don't think I'm missing anything in my (web) app's lib directory.

like image 975
Jack Avatar asked Apr 23 '17 18:04

Jack


People also ask

What is Pylint in Visual Studio?

PyLint, a widely used tool that checks for errors in Python code and encourages good Python coding patterns, is integrated into Visual Studio for Python projects.

How do I fix Pylint import error in VSCode?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.

What is Pylint linter?

Pylint is a static code analysis tool for the Python programming language. It is named following a common convention in Python of a "py" prefix, and a nod to the C programming lint program. It follows the style recommended by PEP 8, the Python style guide.


2 Answers

Changing the library path worked for me. Hitting Ctrl + Shift + P and typing python interpreter and choosing one of the available shown. One was familiar (as pointed to a virtualenv that was working fine earlier) and it worked. Take note of the version of python you are working with, either 2.7 or 3.x and choose accordingly

like image 72
Ivan_ug Avatar answered Sep 27 '22 18:09

Ivan_ug


I was facing same issue (VS Code).Resolved by below method

1) Select Interpreter command from the Command Palette (Ctrl+Shift+P)

2) Search for "Select Interpreter"

3) Select the installed python directory

Ref:- https://code.visualstudio.com/docs/python/environments#_select-an-environment

like image 27
SurajKj Avatar answered Sep 27 '22 20:09

SurajKj