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

Get activate env vars for non-conda as well #9163

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion src/client/datascience/kernel-launcher/kernelEnvVarsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class KernelEnvironmentVariablesService {

let [customEditVars, interpreterEnv] = await Promise.all([
this.customEnvVars.getCustomEnvironmentVariables(resource).catch(noop),
interpreter && interpreter.envType == EnvironmentType.Conda
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong, we should get activated env variables for Virtual Env, etc, not just Conda environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work for virtual environments

interpreter
? this.envActivation
.getActivatedEnvironmentVariables(resource, interpreter, false)
.catch<undefined>((ex) => {
Expand All @@ -62,6 +62,14 @@ export class KernelEnvironmentVariablesService {
]);
if (!interpreterEnv && Object.keys(customEditVars || {}).length === 0) {
traceInfo('No custom variables nor do we have a conda environment');
// Ensure the python env folder is always at the top of the PATH, this way all executables from that env are used.
// This way shell commands such as `!pip`, `!python` end up pointing to the right executables.
// Also applies to `!java` where java could be an executable in the conda bin directory.
if (interpreter) {
const env = kernelEnv || process.env;
this.envVarsService.prependPath(env, path.dirname(interpreter.path));
return env;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fall back, if we do'nt have any env variables, then prefix PATH as we do in other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work for global interpreters

}
return kernelEnv;
}
// Merge the env variables with that of the kernel env.
Expand Down