Skip to content

Wrong Python executable used when running code using PythonExecutionFactory #17613

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
DonJayamanne opened this issue Oct 4, 2021 · 1 comment · Fixed by #17614
Closed

Wrong Python executable used when running code using PythonExecutionFactory #17613

DonJayamanne opened this issue Oct 4, 2021 · 1 comment · Fixed by #17614
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@DonJayamanne
Copy link

DonJayamanne commented Oct 4, 2021

Environment data

  • VS Code version: Insiders
  • Extension version (available under the Extensions sidebar): Latest (main branch)
  • OS and version: mac
  • Python version (& distribution if applicable, e.g. Anaconda): N/A
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: N/A

[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

Use the python environment provided when creating a PythonExecutionFactory

Actual behaviour

Wrong Python environment is used when creating a PythonExecutionFactory

This should be pretty evident from the following code

    public async create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService> {
        let { pythonPath } = options;
        if (!pythonPath) {
	  		...
        }
        pythonPath = this.configService.getSettings(options.resource).pythonPath;
   		....
        return createPythonService(
            pythonPath,
            processService,
            this.fileSystem,
            undefined,
            await windowsStoreInterpreterCheck(pythonPath),
        );
    }

If you look at the above code, pythonPath is always deafulting to pythonPath defined in settings.json even if a PythonPath has been provided in options

This causes issues in Jupyter extension as its not using the python path provided in options

@karthiknadig @karrtikr /cc

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Oct 4, 2021
@DonJayamanne
Copy link
Author

I'd submit a PR, looks simple enough, but not sure what we were attempting to fix when this code was changed.
The solution looks simple as follows:

        if (!pythonPath) {
	        pythonPath = this.configService.getSettings(options.resource).pythonPath;
        }

Get pythonPath from settings only if its empty.

@karrtikr karrtikr self-assigned this Oct 4, 2021
@karrtikr karrtikr added area-environments Features relating to handling interpreter environments needs PR regression Bug didn't exist in a previous release and removed triage-needed Needs assignment to the proper sub-team labels Oct 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release
Projects
None yet
2 participants