Skip to content

Slashes not escaped in paths when activating conda environments in Git Bash on Windows #11419

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
keithyipkw opened this issue Apr 26, 2020 · 14 comments
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug

Comments

@keithyipkw
Copy link

Upon opening a new Bash,

$ C:\ProgramData\Anaconda3\Scripts\activate mkl
bash: C:ProgramDataAnaconda3Scriptsactivate: command not found

The correct command should be using escaped backslashes or forward slashes

$ C:\\ProgramData\\Anaconda3\\Scripts\\activate mkl
$ C:/ProgramData/Anaconda3/Scripts/activate mkl

Interestingly, the command for activating the base environment is

$ C:/ProgramData/Anaconda3/Scripts/activate

Environment data

  • VS Code version: 1.44.2
  • Extension version (available under the Extensions sidebar): 2020.4.74986
  • OS and version: Windows_NT x64 10.0.18362
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 4.8.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: all
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): true
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

The environment is activated.

Actual behaviour

"command not found" is displayed.

Steps to reproduce:

  1. Ensure python.terminal.activateEnvironment to be true
  2. Select an Anaconda environment other than the base
  3. Open a new terminal

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

Activating environments other than the base

workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:14: getActivatedEnvironmentVariables, Class name = _, completed in 381ms, has a truthy return value, Arg 1: undefined
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Shell path 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Shell path identified as shell 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Terminal name 'bash' identified as shell 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: [object Object]. Shell identified as bash (Terminal name is bash)
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Shell identified as 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Get Conda environments, Class name = b, completed in 0ms, has a truthy return value, Arg 1: false, Return Value: [{"name":"base","path":"C:\\ProgramData\\Anaconda3"},{"name":"mkl","path":"C:\\Users\\user\\.conda\\envs\\mkl"},{"name":"py2","path":"C:\\Users\\user\\.conda\\envs\\py2"},{"name":"py27_32","path":"C:\\Users\\user\\.conda\\envs\\py27_32"}]
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaVersion-Args=
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaFileFromInterpreter-Args="C:\\Users\\user\\.conda\\envs\\mkl\\python.exe"-Arg-Separator-"mkl"
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:04:18: Get Conda File from interpreter, Class name = b, completed in 0ms, has a falsy return value, Arg 1: "C:\\Users\\user\\.conda\\envs\\mkl\\python.exe", Arg 2: "mkl", Return Value: undefined

Activiting the base

workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Shell path 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Shell path identified as shell 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Terminal name 'bash' identified as shell 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: [object Object]. Shell identified as bash (Terminal name is bash)
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Shell identified as 'bash'
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Get Conda environments, Class name = b, completed in 0ms, has a truthy return value, Arg 1: false, Return Value: [{"name":"base","path":"C:\\ProgramData\\Anaconda3"},{"name":"mkl","path":"C:\\Users\\user\\.conda\\envs\\mkl"},{"name":"py2","path":"C:\\Users\\user\\.conda\\envs\\py2"},{"name":"py27_32","path":"C:\\Users\\user\\.conda\\envs\\py27_32"}]
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaVersion-Args=
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaFileFromInterpreter-Args="C:\\ProgramData\\Anaconda3\\python.exe"-Arg-Separator-"base"
workbench.desktop.main.js:sourcemap:262 [Extension Host] Info Python Extension: 2020-04-26 15:07:35: Get Conda File from interpreter, Class name = b, completed in 0ms, has a truthy return value, Arg 1: "C:\\ProgramData\\Anaconda3\\python.exe", Arg 2: "base", Return Value: "C:\\ProgramData\\Anaconda3\\Scripts\\conda.exe"
@keithyipkw keithyipkw added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Apr 26, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 29, 2020
@kimadeline
Copy link

Hello @keithyipkw, thank you for reaching out.

What is the value for terminal.integrated.shell.windows in your user settings and in your workspace settings? When you say bash, do you mean the WSL shell? Does this issue only happen with this shell, or with Powershell and the command prompt as well?

Thanks!

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Apr 29, 2020
@keithyipkw
Copy link
Author

keithyipkw commented Apr 30, 2020

Hello @keithyipkw, thank you for reaching out.

What is the value for terminal.integrated.shell.windows in your user settings and in your workspace settings? When you say bash, do you mean the WSL shell? Does this issue only happen with this shell, or with Powershell and the command prompt as well?

Thanks!

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

@kimadeline
Copy link

Is this from your user settings, or your workspace settings (the .vscode/settings.json file in your folder)?

@keithyipkw
Copy link
Author

Is this from your user settings, or your workspace settings (the .vscode/settings.json file in your folder)?

It is from my user settings.

@kimadeline
Copy link

Sorry for the late reply @keithyipkw (was working on issues related to Windows Store installations of Python, so I had to scrub out and then setup conda again) but I couldn't reproduce your issue:

image

What's the content of your .vscode/settings.json file? And what is the path being displayed when you select your interpreter:

image

Thank you!

@keithyipkw
Copy link
Author

keithyipkw commented May 13, 2020

What's the content of your .vscode/settings.json file? And what is the path being displayed when you select your interpreter:

image

The activation command is correct if I select "base". It is wrong only if I select any other environments.

.vscode/settings.json

{
    "python.pythonPath": "C:\\Users\\user\\.conda\\envs\\mkl\\python.exe"
}

The path for the interpreter is

~\.conda\envs\mkl\python.exe

For comparison, they are the following for "base"

{
    "python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe"
}
C:\ProgramData\Anaconda3\python.exe

@kimadeline
Copy link

When you write .conda in your settings and interpreter path, is this a shorthand for anaconda/miniconda, or is your environment folder actually named .conda?

It's also pretty strange that you get a full length activation command (C:\ProgramData\Anaconda3\Scripts\activate mkl) when it should be a 2-step process (C:\\ProgramData\\Anaconda3\\Scripts\\activate followed by conda activate mkl).

How did you create the mkl environment?

@keithyipkw
Copy link
Author

When you write .conda in your settings and interpreter path, is this a shorthand for anaconda/miniconda, or is your environment folder actually named .conda?

It's also pretty strange that you get a full length activation command (C:\ProgramData\Anaconda3\Scripts\activate mkl) when it should be a 2-step process (C:\\ProgramData\\Anaconda3\\Scripts\\activate followed by conda activate mkl).

How did you create the mkl environment?

Which properties in which VS settings did you mean?

Annotation 2020-05-23 223116

settings.json in AppData

{
    "workbench.colorTheme": "Visual Studio Light",
    "editor.fontFamily": "'Source Code Pro', 'Courier New', monospace",
    "editor.fontSize": 15,
    "editor.autoSurround": "never",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "workbench.startupEditor": "none",
    "editor.smoothScrolling": true,
    "editor.mouseWheelScrollSensitivity": 0.75,
    "editor.wordWrap": "on",
    "editor.find.seedSearchStringFromSelection": false,
    "latex-workshop.view.pdf.viewer": "tab",
    "window.zoomLevel": 0,
    "python.condaPath": "C:\\ProgramData\\Anaconda3\\Scripts\\conda.exe",
    "python.terminal.activateEnvInCurrentTerminal": true,
    "terminal.integrated.shellArgs.windows": ["-l"],
}

.vs/settings.json

{
    "python.pythonPath": "C:\\Users\\user\\.conda\\envs\\mkl\\python.exe"
}

It is a 2-step process for activating my base

$ C:/ProgramData/Anaconda3/Scripts/activate

$ conda activate base

Comparing to selecting a non-base env

$ C:\ProgramData\Anaconda3\Scripts\activate mkl
bash: C:ProgramDataAnaconda3Scriptsactivate: command not found

I created my envs in Anaconda Prompt following this doc https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
They were something like this

conda create -n myenv python=3.6

@kimadeline
Copy link

kimadeline commented May 26, 2020

Good news: I think we're getting closer to figuring out why you are getting 2 different activation commands 🔎

In condaActivationProvider.ts we have some code that activates environments differently depending on your version of conda:

  • if conda is > 4.6 and we're not using powershell then we send 2 activation commands (what you see with base);
  • otherwise we send one activation command (what is happening with mkl).

Now, I know you mentioned in your original command that you use Anaconda 4.8.2, can you run the following commands outside of VS Code, and copy their output here, so we can try and narrow down where the extension trips up:

  • conda --version when you have the base environment activated
  • conda --version when you have the mkl environment activated
  • conda info --json when you have the base environment activated
  • conda info --json when you have the mkl environment activated

Thank you for your help!

@keithyipkw
Copy link
Author

(base) C:\Users\user>conda --version
conda 4.8.2

(base) C:\Users\user>conda info --json
{
  "active_prefix": "C:\\ProgramData\\Anaconda3",
  "active_prefix_name": "base",
  "channels": [
    "https://repo.anaconda.com/pkgs/main/win-64",
    "https://repo.anaconda.com/pkgs/main/noarch",
    "https://repo.anaconda.com/pkgs/r/win-64",
    "https://repo.anaconda.com/pkgs/r/noarch",
    "https://repo.anaconda.com/pkgs/msys2/win-64",
    "https://repo.anaconda.com/pkgs/msys2/noarch"
  ],
  "conda_build_version": "3.18.11",
  "conda_env_version": "4.8.2",
  "conda_location": "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\conda",
  "conda_prefix": "C:\\ProgramData\\Anaconda3",
  "conda_private": false,
  "conda_shlvl": 1,
  "conda_version": "4.8.2",
  "config_files": [
    "C:\\Users\\user\\.condarc"
  ],
  "default_prefix": "C:\\ProgramData\\Anaconda3",
  "env_vars": {
    "AMDPROFILERPATH": "C:\\Program Files\\AMD\\AMDuProf\\bin",
    "AMDRMPATH": "C:\\Program Files\\AMD\\RyzenMaster\\",
    "CIO_TEST": "<not set>",
    "CONDA_BAT": "C:\\ProgramData\\Anaconda3\\condabin\\conda.bat",
    "CONDA_DEFAULT_ENV": "base",
    "CONDA_EXE": "C:\\ProgramData\\Anaconda3\\condabin\\..\\Scripts\\conda.exe",
    "CONDA_EXES": "\"C:\\ProgramData\\Anaconda3\\condabin\\..\\Scripts\\conda.exe\"  ",
    "CONDA_PREFIX": "C:\\ProgramData\\Anaconda3",
    "CONDA_PROMPT_MODIFIER": "(base) ",
    "CONDA_PYTHON_EXE": "C:\\ProgramData\\Anaconda3\\python.exe",
    "CONDA_ROOT": "C:\\ProgramData\\Anaconda3",
    "CONDA_SHLVL": "1",
    "HOMEPATH": "\\Users\\user",
    "PATH": "C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\ProgramData\\Anaconda3\\bin;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\ProgramData\\Anaconda3\\bin;C:\\ProgramData\\Anaconda3\\condabin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files (x86)\\Kensington\\TrackballWorks;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NGX;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\Program Files\\dotnet;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn;C:\\Program Files\\Java\\jdk-13.0.1\\bin;C:\\Program Files\\AMD\\AMDuProf\\bin;C:\\texlive\\2020\\bin\\win32;C:\\Program Files\\SourceGear\\Common\\DiffMerge;C:\\Ruby26-x64\\bin;C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\user\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Bandizip;C:\\Users\\user\\.dotnet\\tools",
    "PSMODULEPATH": "C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules;C:\\Program Files\\Intel\\Wired Networking\\",
    "REQUESTS_CA_BUNDLE": "<not set>",
    "SSL_CERT_FILE": "<not set>",
    "VBOX_MSI_INSTALL_PATH": "C:\\Program Files\\Oracle\\VirtualBox\\"
  },
  "envs": [
    "C:\\ProgramData\\Anaconda3",
    "C:\\Users\\user\\.conda\\envs\\mkl",
    "C:\\Users\\user\\.conda\\envs\\py2",
    "C:\\Users\\user\\.conda\\envs\\py27_32"
  ],
  "envs_dirs": [
    "C:\\Users\\user\\.conda\\envs",
    "C:\\ProgramData\\Anaconda3\\envs",
    "C:\\Users\\user\\AppData\\Local\\conda\\conda\\envs"
  ],
  "is_windows_admin": false,
  "netrc_file": null,
  "offline": false,
  "pkgs_dirs": [
    "C:\\ProgramData\\Anaconda3\\pkgs",
    "C:\\Users\\user\\.conda\\pkgs",
    "C:\\Users\\user\\AppData\\Local\\conda\\conda\\pkgs"
  ],
  "platform": "win-64",
  "python_version": "3.7.6.final.0",
  "rc_path": "C:\\Users\\user\\.condarc",
  "requests_version": "2.22.0",
  "root_prefix": "C:\\ProgramData\\Anaconda3",
  "root_writable": false,
  "site_dirs": [
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python27",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python36",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python37",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Scripts"
  ],
  "sys.executable": "C:\\ProgramData\\Anaconda3\\python.exe",
  "sys.prefix": "C:\\ProgramData\\Anaconda3",
  "sys.version": "3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]",
  "sys_rc_path": "C:\\ProgramData\\Anaconda3\\.condarc",
  "user_agent": "conda/4.8.2 requests/2.22.0 CPython/3.7.6 Windows/10 Windows/10.0.18362",
  "user_rc_path": "C:\\Users\\user\\.condarc",
  "virtual_pkgs": [
    [
      "__cuda",
      "10.1"
    ]
  ]
}
(mkl) C:\Users\user>conda --version
conda 4.8.2

(mkl) C:\Users\user>conda info --json
{
  "active_prefix": "C:\\Users\\user\\.conda\\envs\\mkl",
  "active_prefix_name": "mkl",
  "channels": [
    "https://repo.anaconda.com/pkgs/main/win-64",
    "https://repo.anaconda.com/pkgs/main/noarch",
    "https://repo.anaconda.com/pkgs/r/win-64",
    "https://repo.anaconda.com/pkgs/r/noarch",
    "https://repo.anaconda.com/pkgs/msys2/win-64",
    "https://repo.anaconda.com/pkgs/msys2/noarch"
  ],
  "conda_build_version": "3.18.11",
  "conda_env_version": "4.8.2",
  "conda_location": "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\conda",
  "conda_prefix": "C:\\ProgramData\\Anaconda3",
  "conda_private": false,
  "conda_shlvl": 2,
  "conda_version": "4.8.2",
  "config_files": [
    "C:\\Users\\user\\.condarc"
  ],
  "default_prefix": "C:\\Users\\user\\.conda\\envs\\mkl",
  "env_vars": {
    "AMDPROFILERPATH": "C:\\Program Files\\AMD\\AMDuProf\\bin",
    "AMDRMPATH": "C:\\Program Files\\AMD\\RyzenMaster\\",
    "CIO_TEST": "<not set>",
    "CONDA_BAT": "C:\\ProgramData\\Anaconda3\\condabin\\conda.bat",
    "CONDA_DEFAULT_ENV": "mkl",
    "CONDA_EXE": "C:\\ProgramData\\Anaconda3\\condabin\\..\\Scripts\\conda.exe",
    "CONDA_EXES": "\"C:\\ProgramData\\Anaconda3\\condabin\\..\\Scripts\\conda.exe\"  ",
    "CONDA_PREFIX": "C:\\Users\\user\\.conda\\envs\\mkl",
    "CONDA_PREFIX_1": "C:\\ProgramData\\Anaconda3",
    "CONDA_PROMPT_MODIFIER": "(mkl) ",
    "CONDA_PYTHON_EXE": "C:\\ProgramData\\Anaconda3\\python.exe",
    "CONDA_ROOT": "C:\\ProgramData\\Anaconda3",
    "CONDA_SHLVL": "2",
    "HOMEPATH": "\\Users\\user",
    "PATH": "C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\ProgramData\\Anaconda3\\bin;C:\\Users\\user\\.conda\\envs\\mkl;C:\\Users\\user\\.conda\\envs\\mkl\\Library\\mingw-w64\\bin;C:\\Users\\user\\.conda\\envs\\mkl\\Library\\usr\\bin;C:\\Users\\user\\.conda\\envs\\mkl\\Library\\bin;C:\\Users\\user\\.conda\\envs\\mkl\\Scripts;C:\\Users\\user\\.conda\\envs\\mkl\\bin;C:\\ProgramData\\Anaconda3\\condabin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files (x86)\\Kensington\\TrackballWorks;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NGX;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\Program Files\\dotnet;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn;C:\\Program Files\\Java\\jdk-13.0.1\\bin;C:\\Program Files\\AMD\\AMDuProf\\bin;C:\\texlive\\2020\\bin\\win32;C:\\Program Files\\SourceGear\\Common\\DiffMerge;C:\\Ruby26-x64\\bin;C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\user\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Bandizip;C:\\Users\\user\\.dotnet\\tools",
    "PSMODULEPATH": "C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules;C:\\Program Files\\Intel\\Wired Networking\\",
    "REQUESTS_CA_BUNDLE": "<not set>",
    "SSL_CERT_FILE": "<not set>",
    "VBOX_MSI_INSTALL_PATH": "C:\\Program Files\\Oracle\\VirtualBox\\"
  },
  "envs": [
    "C:\\ProgramData\\Anaconda3",
    "C:\\Users\\user\\.conda\\envs\\mkl",
    "C:\\Users\\user\\.conda\\envs\\py2",
    "C:\\Users\\user\\.conda\\envs\\py27_32"
  ],
  "envs_dirs": [
    "C:\\Users\\user\\.conda\\envs",
    "C:\\ProgramData\\Anaconda3\\envs",
    "C:\\Users\\user\\AppData\\Local\\conda\\conda\\envs"
  ],
  "is_windows_admin": false,
  "netrc_file": null,
  "offline": false,
  "pkgs_dirs": [
    "C:\\ProgramData\\Anaconda3\\pkgs",
    "C:\\Users\\user\\.conda\\pkgs",
    "C:\\Users\\user\\AppData\\Local\\conda\\conda\\pkgs"
  ],
  "platform": "win-64",
  "python_version": "3.7.6.final.0",
  "rc_path": "C:\\Users\\user\\.condarc",
  "requests_version": "2.22.0",
  "root_prefix": "C:\\ProgramData\\Anaconda3",
  "root_writable": false,
  "site_dirs": [
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python27",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python36",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Python37",
    "C:\\Users\\user\\AppData\\Roaming\\Python\\Scripts"
  ],
  "sys.executable": "C:\\ProgramData\\Anaconda3\\python.exe",
  "sys.prefix": "C:\\ProgramData\\Anaconda3",
  "sys.version": "3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]",
  "sys_rc_path": "C:\\ProgramData\\Anaconda3\\.condarc",
  "user_agent": "conda/4.8.2 requests/2.22.0 CPython/3.7.6 Windows/10 Windows/10.0.18362",
  "user_rc_path": "C:\\Users\\user\\.condarc",
  "virtual_pkgs": [
    [
      "__cuda",
      "10.1"
    ]
  ]
}

@kimadeline kimadeline removed the info-needed Issue requires more information from poster label Jun 7, 2020
@kimadeline
Copy link

Ok, I think that's it:

This is the logic to build the activation command if your conda version is > 4.6:

const interpreterPath = await this.condaService.getCondaFileFromInterpreter(pythonPath, envInfo.name);
if (interpreterPath) {
const activatePath = path.join(path.dirname(interpreterPath), 'activate').fileToCommandArgument();
const firstActivate = this.platform.isWindows ? activatePath : `source ${activatePath}`;
return [firstActivate, `conda activate ${condaEnv.toCommandArgument()}`];
}

However getCondaFileFromInterpreter returns undefined from the logs you posted in your original comment ➡️ this logic gets bypassed ➡️ we fall back to the default Windows command, which seems to not escape slashes properly.

We have 2 issues here:

  • getCondaFileFromInterpreter's logic having holes, which should be addressed when we refactor interpreter discovery in Refactor interpreter discovery #12020 (feel free to upvote it!);
  • incorrect escaping of the backslashes, which I could also reproduce.

I'll update the title of this issue to focus on problem 2.

Thank you again for your patience!


Repro conditions:

  • Windows, Git Bash as my terminal, conda 4.8.2
  • Create a conda environment with a prefix (conda create -p path/to/a/folder python=python3.8)
  • Set the interpreter to be the executable from this conda environment
  • Open terminal and watch auto-activation fail:

image

@kimadeline kimadeline changed the title Incorrect slashes in paths when activating environments other than base for Anaconda in new Bash on Windows Slashes not escaped in paths when activating conda environments in Git Bash on Windows Jun 9, 2020
@kimadeline kimadeline removed their assignment Jun 9, 2020
@kimadeline kimadeline added area-environments Features relating to handling interpreter environments reason-preexisting and removed triage labels Jun 9, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jun 9, 2020
@kimadeline kimadeline added needs PR and removed triage-needed Needs assignment to the proper sub-team labels Jun 9, 2020
@AJMansfield
Copy link

AJMansfield commented Mar 25, 2021

Environment Path

When you write .conda in your settings and interpreter path, is this a shorthand for anaconda/miniconda, or is your environment folder actually named .conda?

A user's %HOME%\.conda\envs directory is the default path for creating environments on a lot of anaconda installs. (And especially for environments intended for e.g. use a a jupyter kernel, or for experimentation, this is a pretty reasonable default, even if for a larger production project you'd probably want to specify putting the project-specific environment in the project folder.)

For instance, here's the output of running a conda create command from git bash:

testuser@DESKTOP-TEST MINGW64 ~
$ conda create --name testenv --yes
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\testuser\.conda\envs\testenv



Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate testenv
#
# To deactivate an active environment, use
#
#     $ conda deactivate


My Current Workaround for This Issue

Note that this conda command is not actually an executable on my system path, it's a shell function defined in this script provided by the anaconda installer.
On both windows and linux, the anaconda installer presents the option to automatically add a line to the user's .bashrc to source this script, and in my case the relevant .bashrc line is:

. /c/ProgramData/Anaconda3/etc/profile.d/conda.sh

Since I'm using Git Bash as my default VSC terminal, this all gets sourced when the VSC terminal starts the same way it does when I open the shell externally, and at the moment my usual workflow is precisely to run this conda activate testenv command after the python extension tries and fails to run its own version of the activation command:

testuser@DESKTOP-TEST MINGW64 ~
$ C:\ProgramData\Anaconda3\Scripts\activate testenv
bash: C:ProgramDataAnaconda3Scriptsactivate: command not found

testuser@DESKTOP-TEST MINGW64 ~
$ conda activate testenv
(testenv) 
testuser@DESKTOP-TEST MINGW64 ~
$ python whatever.py

I suppose one obvious solution here would be to allow users to manually specify the full activation command they want to use rather than restricting it to just a single path (as in the current python.condaPath setting), and then I could instruct the extension to just run the conda activate testenv command I currently do manually, and you might want to add this anyway even though there's also another potential way to fix this issue that I've figured out.

A Potential Fix

Outside if the ability to just specify a fully-custom command, there's a few different ways that I've determined that the C:\ProgramData\Anaconda3\Scripts\activate script can be successfully run in the bash shell, the way that the extension is attempting to do:

  • Converting it to a unix-style path: $ /c/ProgramData/Anaconda3/Scripts/activate testenv
  • Placing the windows-style path in single quotes: $ 'C:\ProgramData\Anaconda3\Scripts\activate' testenv
  • Placing the windows-style path in double quotes: $ "C:\ProgramData\Anaconda3\Scripts\activate" testenv

Note that the last one, double quoting, is particularly interesting, as the default windows CMD prompt also allows commands to be double-quoted, meaning that this single way of formatting it is portable across both shells.

In the windows CMD:

C:\Users\testuser>"C:\ProgramData\Anaconda3\Scripts\activate" testenv

In windows git bash:

testuser@DESKTOP-TEST MINGW64 ~
$ "C:\ProgramData\Anaconda3\Scripts\activate" testenv

It seems like a straightforward solution would be to modify the way the program generates this command string, to just always include double quotes even when the path its running doesn't seem to have any spaces or other characters that would need to be quoted/escaped under windows CMD.
This probably isn't the "proper" way to fix this problem, but adding quotes like this can only improve portability, and in this case would probably be sufficient to resolve this issue.

Based on my cursory perusal of the source code, it seems like the getWindowsActivateCommand function would probably be the place to add this behavior, although this is my first time looking at this codebase so I could be completely off-base here; In any case I'm not really fluent enough in typescript to be confident in proposing the code change myself.

@rezanaima
Copy link

Has any progress been made on resolving this issue as I also suffer from it?

Also - I've tried but not been able to get any output akin to what was described from the developers console when switching environments. Is there some debugging mode/level that I need to turn on first? Also, I've

Enable source map support for extension debugging

But I've not found a way to disable it. Does it turn off when visual code restarts?

@keithyipkw
Copy link
Author

The problem no longer exists in my system after updating my VC Code to the latest version, 1.69.1, from an ancient version. It becomes a two-step process same as cmd. I am not sure if the update or some changes to my environment before (if any) fixed the problem.

(base)
<user> MINGW64 ~/ (master)
$ C:/ProgramData/Anaconda3/Scripts/activate
(base) 
<user> MINGW64 ~/ (master)
$ conda activate 38
(38) 
<user> MINGW64 ~/ (master)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2022
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
Projects
None yet
Development

No branches or pull requests

5 participants