Skip to content
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

fix python env activation issues #686

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { request as httpRequest } from 'http';
import { request as httpsRequest } from 'https';
import { IDisposable, IEnvironmentType, IPythonEnvironment } from './tokens';
import {
activatePathForEnvPath,
createTempFile,
getEnvironmentPath,
getFreePort,
getSchemasDir,
getUserDataDir,
waitForDuration
} from './utils';
Expand All @@ -32,7 +32,6 @@ const SERVER_RESTART_LIMIT = 3; // max server restarts
function createLaunchScript(
serverInfo: JupyterServer.IInfo,
baseCondaPath: string,
schemasDir: string,
port: number,
token: string
): string {
Expand Down Expand Up @@ -71,6 +70,7 @@ function createLaunchScript(
// conda-packed environments

let condaActivatePath = '';
let condaShellScriptPath = '';
let isBaseCondaActivate = true;

// use activate from the environment instead of base when possible
Expand All @@ -94,10 +94,18 @@ function createLaunchScript(
isBaseCondaActivate = false;
} else {
condaActivatePath = path.join(baseCondaPath, 'bin', 'activate');
condaShellScriptPath = path.join(
baseCondaPath,
'etc',
'profile.d',
'conda.sh'
);
}
}
}

const envActivatePath = activatePathForEnvPath(envPath);

if (isWin) {
if (isConda) {
script = `
Expand All @@ -106,18 +114,22 @@ function createLaunchScript(
CALL ${launchCmd}`;
} else {
script = `
CALL ${envPath}\\activate.bat
CALL ${envActivatePath}
CALL ${launchCmd}`;
}
} else {
if (isConda) {
script = `
source "${condaActivatePath}"
${isBaseCondaActivate ? `conda activate "${envPath}"` : ''}
${
isBaseCondaActivate
? `source ${condaShellScriptPath} && conda activate "${envPath}"`
: ''
}
${launchCmd}`;
} else {
script = `
source "${envPath}/bin/activate"
source "${envActivatePath}"
${launchCmd}`;
}
}
Expand Down Expand Up @@ -264,7 +276,6 @@ export class JupyterServer {
const launchScriptPath = createLaunchScript(
this._info,
baseCondaPath,
getSchemasDir(),
this._info.port,
this._info.token
);
Expand Down