Haifeng Zhang
Haifeng Zhang

Reputation: 31905

Python refactoring fails in Visual Studio Code

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

Upvotes: 13

Views: 17603

Answers (3)

HauiB
HauiB

Reputation: 159

On Ubuntu, miniconda: I had this issue using the "VSCode Python Plugin", when selecting "conda" install for rope.

I changed the active env with Terminal using "conda activate env". Then with "conda list", I saw Build Row was at value py_0 and at version 0.16. I've chosen conda remove rope Then, installing with pip (rope version 0.17.0): pip install rope "conda list" gave me now pypi_0 as value in Build row Restart VSCode

Summarize, one of this helped:
- Reinstalling rope with pip in the active conda environment
- Restarting VSCode

Upvotes: 0

AnneTheAgile
AnneTheAgile

Reputation: 10260

Update from the filed bug: Anaconda users need to install the Anaconda package instead of the regular pip default install that Visual Studio Code provides.

This worked for me:

conda search rope # The latest right now is 0.11.0
conda install --name mypy27env rope

Upvotes: 2

Don
Don

Reputation: 6882

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.

Upvotes: 13

Related Questions