Skip to content

It is not detecting my interpreter automatically #16664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
omidshojaee opened this issue Jul 13, 2021 · 9 comments
Closed

It is not detecting my interpreter automatically #16664

omidshojaee opened this issue Jul 13, 2021 · 9 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@omidshojaee
Copy link

Environment data

  • VS Code version: 1.58.0
  • Extension version (available under the Extensions sidebar): 2021.6.944021595
  • OS and version: Windows 10 Pro 10.0.19043
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: Default

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

I'm working with Python extension for a year now. I always received a prompt about "detecting the Python interpreter" right after creating the virtual environment. Now that prompt is not showing up anymore so I have to set the interpreter manually.

Actual behaviour

No prompt is showing up about Python interpreter after creating the virtual environment python -m venv venv.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. XXX

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

@omidshojaee omidshojaee added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jul 13, 2021
@karthiknadig karthiknadig added triage and removed triage-needed Needs assignment to the proper sub-team labels Jul 13, 2021
@karthiknadig
Copy link
Member

Duplicate of #16613

@karthiknadig karthiknadig marked this as a duplicate of #16613 Jul 13, 2021
@omidshojaee
Copy link
Author

@karthiknadig
As you locked me out of #16613 I send you this here.

This is the prompt everyone is talking about:

hqdefault

@karthiknadig
Copy link
Member

This prompt, again, comes form python extension only when it is activated (I have pasted links to actual code in the extension that does the detections and shows you that literal prompt) . You are seeing this prompt because the python extension was activated when you created the virtual env so it was able to detect it automatically. VS Code does not know about python environments, the python extension for VS Code does.

Here is where we detect that the environment was created:

// Call callback if an environment gets created within the resource provided.
public onDidCreate(resource: Resource, callback: () => void): vscode.Disposable {
const workspaceFolder = resource ? vscode.workspace.getWorkspaceFolder(resource) : undefined;
return this.api.onChanged((e) => {
if (!workspaceFolder || !e.searchLocation) {
return;
}
if (
e.type === FileChangeType.Created &&
isParentPath(e.searchLocation.fsPath, workspaceFolder.uri.fsPath)
) {
callback();
}
});
}

We create the prompt here:

protected async notifyUser(interpreter: PythonEnvironment, resource: Uri): Promise<void> {
const notificationPromptEnabled = this.persistentStateFactory.createWorkspacePersistentState(
doNotDisplayPromptStateKey,
true,
);
if (!notificationPromptEnabled.value) {
return;
}
const prompts = [Common.bannerLabelYes(), Common.bannerLabelNo(), Common.doNotShowAgain()];
const telemetrySelections: ['Yes', 'No', 'Ignore'] = ['Yes', 'No', 'Ignore'];
const selection = await this.appShell.showInformationMessage(
Interpreters.environmentPromptMessage(),
...prompts,
);
sendTelemetryEvent(EventName.PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT, undefined, {
selection: selection ? telemetrySelections[prompts.indexOf(selection)] : undefined,
});
if (!selection) {
return;
}
if (selection === prompts[0]) {
await this.pythonPathUpdaterService.updatePythonPath(
interpreter.path,
ConfigurationTarget.WorkspaceFolder,
'ui',
resource,
);
} else if (selection === prompts[2]) {
await notificationPromptEnabled.updateValue(false);
}
}

You can literally see the text of the prompt here:

export const environmentPromptMessage = localize(
'Interpreters.environmentPromptMessage',
'We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?',
);

I understand that for you this was some how working before. The point we are trying to tell you is that for this to work the extension had to be activated. So previously the extension was getting activated for you some how. We need to figure out why that was the case, and why it stopped activating.

To understand what might be broken or failing here, we need to know if it works at all when activated. If it works when activated, then the next step is to figure out why extension is not activating in cases where it was previously activating for you. If we understand these two things we can get you where you were before this issue began.

You can try reverting to an older version of the extension to see if it works for you.

@omidshojaee
Copy link
Author

I'm a user and not interested in the technical part.

The prompt was working for many, not just me.

It is not working now even when the extension is activated by opening a python file.

And I wonder, if it is a fresh install of VSCode and python extension, and it is the user's first project, how it is possible to activate the extension because there is no python file available to user before creating the virtual environment?

@omidshojaee
Copy link
Author

Perhaps the extension used to monitor the file system and detect the presence of python.exe ?

@omidshojaee
Copy link
Author

@karthiknadig
I tested with 2021.5.926500501 and the prompt appeared after creating the virtual environment.

@brettcannon
Copy link
Member

@omidshojaee a virtual environment is not required to create a Python file as the virtual environment should be a subdirectory of your workspace (if they are creating a virtual environment locally). And a lot of users don't even create a virtual environment for their first project. Lastly, we try to detect local virtual environments in the workspace at start-up of the extension. We also automatically activate if certain files are present in your workspace (e.g. pyproject.toml).

@brettcannon
Copy link
Member

And please understand we locked the other issue due to the tone that was being taken with us and the team. I'm happy to answer your question here as long as it stays respectful like it has so far on this issue.

@omidshojaee

This comment has been minimized.

@microsoft microsoft locked as too heated and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants