VS Code Doesnt Recognize Python Virtual Environment

2024/11/15 0:54:42

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

It seems that now is called python.defaultInterpreterPath

https://en.xdnf.cn/q/72318.html

Related Q&A

Why codecs.iterdecode() eats empty strings?

Why the following two decoding methods return different results?>>> import codecs >>> >>> data = [, , a, ] >>> list(codecs.iterdecode(data, utf-8)) [ua] >>>…

How to keep NaN in pivot table?

Looking to preserve NaN values when changing the shape of the dataframe.These two questions may be related:How to preserve NaN instead of filling with zeros in pivot table? How to make two NaN as NaN …

Using Pandas df.where on multiple columns produces unexpected NaN values

Given the DataFrameimport pandas as pddf = pd.DataFrame({transformed: [left, right, left, right],left_f: [1, 2, 3, 4],right_f: [10, 20, 30, 40],left_t: [-1, -2, -3, -4],right_t: [-10, -20, -30, -40], }…

Django star rating system and AJAX

I am trying to implement a star rating system on a Django site.Storing the ratings in my models is sorted, as is displaying the score on the page. But I want the users to be able to rate a page (from 1…

Create inheritance graphs/trees for Django templates

Is there any tool out there that would take a directory with a Django application, scan it for templates and draw/print/list a hierarchy of inheritance between templates?Seeing which blocks are being …

Python SVG converter creates empty file

I have some code below that is supposed to convert a SVG image to a PNG. It runs without errors but creates a PNG file that is blank instead of one with the same image as the original SVG. I did find t…

Fastest way to iterate through a pandas dataframe?

How do I run through a dataframe and return only the rows which meet a certain condition? This condition has to be tested on previous rows and columns. For example:#1 #2 #3 #4 1/1/1999 4 …

Constraints do not follow DCP rules in CVXPY

I want to solve this problem using CVXPY but I dont know why I get the following error message:DCPError: Problem does not follow DCP rules. I guess my constraints are not DCP. Is there any way to model…

is this betweenness calculation correct?

I try to calculate betweenness for all nodes for the path from 2 to 6 in this simple graph.G=nx.Graph() edge=[(1,5),(2,5),(3,5),(4,5),(4,6),(5,7),(7,6)] G.add_edges_from(edge) btw=nx.betweenness_centra…

Why does PIL thumbnail not resizing correctly?

I am trying to create and save a thumbnail image when saving the original user image in the userProfile model in my project, below is my code:def save(self, *args, **kwargs):super(UserProfile, self).sa…