Select Code → Preferences → Settings. Alternatively, you can use the shortcut key "command +,".
Click the small icon in the upper right to open it.
A file called settings.json will open. You can edit the destination of the Visual Studio Code path, so set "python.pythonPath ~" here. The path itself depends on your environment, so please set it. If there is a python path here from the beginning, you can overwrite it, and if you do not have it, you can write a new one. Just in case, please be able to restore it.
By the way, I will show you how to check which path python is reading. Seeing is believing, so please take a look at the screenshots first. If you get a quick glance and get "I see", please try it immediately. For those who are a little scared, I will give a brief explanation.
First, start python in your home directory. (To distinguish it from the python2 series originally on the Mac, I started it with the command python3. Please use the command that suits your environment as well)
When python starts, ">>>" will be displayed, so you can interact with python. Type "import sys" and press Enter. (Nothing happens, but that's okay.) Type "import pprint" and press Enter. (Nothing happens, but that's okay.) Type pprint.pprint (sys.path) and press Enter. Here python will tell you the path. Since it is loaded in order from the top, copy the path where the module is located and paste it into settings.json of vscode. You can end the interaction with python with "control + D".
If you do not have the expected path, you will need to pass it through, so please check it separately. In addition, I will omit the details of each command.
Personally, the point is to use pprint. However, when you hear the pass, it is written as sloppy on the side and spit out, so it is very difficult to read ... It is a device to solve it.
Suddenly one day, the module I was using was getting an import error. I forgot the specific error content, but I think it was like "There is no module with that name". I thought that it shouldn't have been possible even though I could use it until then, but suddenly I remembered that I put anyenv and guessed that the destination of the path was changed. First of all, I was messing around with local environment variables (reading destinations of python2 and 3 paths, priority, storage location of modules installed with pip, etc.), but in the end I was messing around with the above. I solved it by the method of. I never thought I would adjust the editor side ... I still haven't trained enough. By the way, I also experienced a crisis situation where no command responded at the terminal while playing with various paths, but this was resolved fairly quickly. (Thanks to all the informants on the internet!)
However, I still have some doubts ... The reason is that only one of the several imports (specifically jaconv) suddenly became unusable. Why did I get such an error even though I could use another module with the same file? And I'm wondering if this solution is the best ... If the cause is found, I will add it.
Recommended Posts