diff --git a/package.json b/package.json index f4b56f9094dc..2f33d88c35d9 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,8 @@ "onCommand:jupyter.execCurrentCellAndAdvance", "onCommand:python.displayHelp", "onCommand:python.buildWorkspaceSymbols", - "onCommand:python.updateSparkLibrary" + "onCommand:python.updateSparkLibrary", + "onCommand:python.startREPL" ], "main": "./out/client/extension", "contributes": { diff --git a/src/client/common/utils.ts b/src/client/common/utils.ts index 470531675a92..35919f3d8641 100644 --- a/src/client/common/utils.ts +++ b/src/client/common/utils.ts @@ -81,6 +81,17 @@ export function getPythonInterpreterDirectory(): Promise { return pythonInterpretterDirectory = ''; }); } +export function getPathFromPythonCommand(args: string[]): Promise { + return execPythonFile(settings.PythonSettings.getInstance().pythonPath, args, __dirname).then(stdout => { + if (stdout.length === 0) { + return ""; + } + let lines = stdout.split(/\r?\n/g).filter(line => line.length > 0); + return validatePath(lines[0]); + }).catch(() => { + return ""; + }); +} export function execPythonFile(file: string, args: string[], cwd: string, includeErrorAsResponse: boolean = false, stdOut: (line: string) => void = null, token?: CancellationToken): Promise { // If running the python file, then always revert to execFileInternal diff --git a/src/client/extension.ts b/src/client/extension.ts index dcf94083387b..d3d47d57b481 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -28,6 +28,7 @@ import { BlockFormatProviders } from './typeFormatters/blockFormatProvider'; import * as os from 'os'; import * as fs from 'fs'; import { activateSingleFileDebug } from './singleFileDebug'; +import { getPathFromPythonCommand } from './common/utils'; const PYTHON: vscode.DocumentFilter = { language: 'python', scheme: 'file' }; let unitTestOutChannel: vscode.OutputChannel; @@ -63,9 +64,13 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, settings.PythonSettings.getInstance(), formatOutChannel)); context.subscriptions.push(vscode.commands.registerCommand(Commands.Start_REPL, () => { - let term = vscode.window.createTerminal('Python', pythonSettings.pythonPath); - term.show(); - context.subscriptions.push(term); + getPathFromPythonCommand(["-c", "import sys;print(sys.executable)"]).catch(()=>{ + return pythonSettings.pythonPath; + }).then(pythonExecutablePath => { + let term = vscode.window.createTerminal('Python', pythonExecutablePath); + term.show(); + context.subscriptions.push(term); + }); })); // Enable indentAction @@ -136,7 +141,12 @@ class PythonExt { private _ensureState(): void { // context: python.isDjangoProject - this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py"))); + if (typeof vscode.workspace.rootPath === 'string'){ + this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py"))); + } + else { + this._isDjangoProject.set(false); + } } }