Python refactoring fails in Visual Studio Code

Haifeng Zhang picture Haifeng Zhang · Jan 26, 2018 · Viewed 13.3k times · Source

I switched to Visual Studio Code for Python programming recently. Below is my Python configuration in Visual Studio Code settings:

"python.pythonPath": "/Users/hzhang/.virtualenvs/env-2.7/bin/python",
"python.autoComplete.extraPaths": [
    "/Users/hzhang/Work/xxx/shared_modules"
],

Basically, I just configure the Python interpreter and add one extra shared module path.

When I try to refactor a variable name, it throws this error which says rope is not installed, and it doesn't work even I install it. Based on my understanding, refactor variables is a feature of Visual Studio Code, and it shouldn't rely on any specific language.

How can I fix this problem?

Enter image description here

Once I installed rope, refactor was still not working. It popups this error:

Enter image description here

I am on Python 2.7
Visual Studio Code: Version 1.19.3 (1.19.3)
Rope version: 0.10.7

Answer

Don picture Don · Jan 27, 2018

Renaming of variables is not a native Visual Studio Code feature for languages other than JavaScript and TypeScript.

It is specific to each language, and functionality is provided by separate extensions, specific to each language. The Python extension you have installed, uses the Rope library to perform refactoring/renaming of python variables and the like. So yes, you'll need to install it by closing in the Install rope button.

If you don't have the Install rope button, you can just go to cmd and type pip install rope. That should do the job as well.

If it doesn't work even after installing it, please could you file an issue on the Python extension GitHub repository.