VS Code Doesn't Recognize Python Virtual Environment

Jim picture Jim · Jun 18, 2019 · Viewed 14.3k times · Source

I'm using VS Code on a Mac to write Python code. I've created a virtual environment named 'venv' inside my project folder and opened VS Code in my project folder. I can see the venv folder in the Explorer pane. However, if I install a package into the virtual environment and I try to import the package into a Python module and then run the module, VS Code raises a ModuleNotFound error saying there is no module.

I followed the instructions in the VS Code document Using Python environments in VS Code by opening the Command Palette, choosing Python: Select Interpreter, and then selecting "venv/bin/folder". But when I do that, I get this error:

Failed to set 'pythonPath'. Error: Unable to write into folder settings.  Please open the 'my_project' folder settings to correct errors/warnings in it and try again.

What are these "folder settings?" I don't see anything in the document I cited above that talks about a folder setting for my virtual environment directory.

Environment:
VS Code 1.35.1
Python for VS Code 0.2.3
Python 3.7.1

UPDATE

Taking @khuynh advice, I opened settings.json and found one error which was that I tried to comment out a line with "//". I didn't realize that JSON files can't include comments.

After taking that line out, I ran "Python: Select Interpreter" again but this time a tab that says .vscode > settings.json >> code-runner.executorMap.python at the top appeared. The tab contained the following code:

    {
        "python.pythonPath": "/usr/local/bin/python3"
        "code-runner.executorMap.python": "python3 -u"
    }

There is a red squiggly line beneath "code-runner.executorMap.python" and the Problems window below says "Unknown configuration setting." I don't understand what's wrong with this setting.

Answer

jjw picture jjw · Jul 6, 2019

Selecting a Python Interpreter does not work if you have errors in your workplace settings file. You are missing a comma after your "python.pythonPath" line.

(I see that others answered this in comments, but I wanted to post an Answer to make this easier for others to find.)