Python refactoring fails in Visual Studio Code
Solution 1
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.
Solution 2
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
Haifeng Zhang
When performance matters, professionals practice. My Site | haifzhan[at]gmail[dot]com My YouTube Channel
Updated on June 03, 2022Comments
-
Haifeng Zhang almost 2 years
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?
Once I installed
rope
, refactor was still not working. It popups this error:I am on Python 2.7 Visual Studio Code: Version 1.19.3 (1.19.3) Rope version: 0.10.7
-
Haifeng Zhang over 6 yearsHey Don. Thanks for your reply. I have installed
rope
before asking the question and it didn't work. -
Don over 6 yearsThanks for updating the issue with further information. Please could you file an issue on github. We'll look into this from there. Looks like the rope library is falling over with some error.
-
Haifeng Zhang over 6 yearspleasesee the comment under my question,the bug has been issued already