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

Conda environment is not activated in current terminal #10942

Closed
JackCaster opened this issue Apr 2, 2020 · 8 comments
Closed

Conda environment is not activated in current terminal #10942

JackCaster opened this issue Apr 2, 2020 · 8 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug

Comments

@JackCaster
Copy link

JackCaster commented Apr 2, 2020

Environment data

  • VS Code version: 1.43.2
  • Extension version (available under the Extensions sidebar): 2020.3.69010
  • OS and version: Win 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Conda 4.8.3

Expected behaviour

Conda env should activate in current terminal on load of the extension

Actual behaviour

Conda env does not activate in current terminal on load of the extension, despite "python.terminal.activateEnvInCurrentTerminal": true.

Possible explanation

This is the same as #10782. I thought I had fixed the problem but I was wrong. What I realized is that the extension does not trigger the .../miniconda/Scripts/activate only for environments with very long names. Try for example to create a new Conda environment with

conda create -n this_is_a_very_long_environment_name python

Everything works fine if I use a shorter name.

@JackCaster JackCaster added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Apr 2, 2020
@Qsi1984
Copy link

Qsi1984 commented Apr 3, 2020

Hi.
I just figured out that I have this exact same issue. Here are some pointers that might help:
Responsible code:

public parseCondaEnvironmentNames(condaEnvironmentList: string): { name: string; path: string }[] | undefined {

If the name is too long, the split-offset is wrong and part of the name is added to the path:

[
    {
        "name": "base",
        "path": "/home/my_user/miniconda3"
    },
    {
        "name": "hpc-quickstart-inferencin",
        "path": "g     /home/my_user/miniconda3/envs/hpc-quickstart-inferencing"
    }
]

which is expected if you have a look at the output of the "conda env list"-command where the / of the base-path aligns with the g that gets clipped from the path of the other environment:

base                  *  /home/u161040/miniconda3
hpc-quickstart-inferencing     /home/u161040/miniconda3/envs/hpc-quickstart-inferencing

hope this helps.

@karthiknadig karthiknadig self-assigned this Apr 7, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 7, 2020
@karthiknadig
Copy link
Member

@Qsi1984 Thank you for taking the time to look into the issue and for the diagnosis. If you would like to make the fix please go ahead.

@karthiknadig karthiknadig added needs PR area-environments Features relating to handling interpreter environments and removed triage labels Apr 10, 2020
@karthiknadig
Copy link
Member

This parsing logic needs to be re-written. Things to take into account:

  1. If base environment is not available then ignore processing further
  2. Make sure that when extracting name only following characters are Not allowed Characters not allowed: ('/', ' ', ':', '#'). This means on non-windows OS there could be "my*env" and it is valid. This also means the current algorithm can misidentify something as a base environment.
  3. Conda environments may not have a name. conda create -p <path> will not have a name.

@tahouse
Copy link

tahouse commented Apr 10, 2020

I am seeing this issue in the Mac OSX version of VS Code as well

Version: 1.44.0
Commit: 2aae1f26c72891c399f860409176fe435a154b13
Date: 2020-04-08T08:23:56.137Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 17.7.0

and ms-python.python version 2020.3.71659 (2 April 2020).

I have tested by cloning a long name environment conda create -n short --clone super_long_name_not_sure_how_many_characters. short will activate automatically in the integrated terminal as expected, but the long name will not.

@Qsi1984
Copy link

Qsi1984 commented Apr 14, 2020

Wouldn't it be saver to use the --json output of the conda env list command instead of parsing stuff? Sadly it does not include a name for the environment only the path to it. But it seems not too hard to replicate the name-logic as it is basically the base-name of the environment-path (see: https://github.com/conda/conda/blob/a7ad4df5882e2ae6bf7a62aecfe94c3c15ea0718/conda/cli/common.py#L181)

@karthiknadig
Copy link
Member

There are a couple of issues with using conda env list --json. It does not provide a way to detect the active environment. Some times it is not clear if a environment has a name.

For a case line this:

base                  *  C:\Anaconda3
                         C:\Anaconda3\envs\issue3\testenv1
testenv1                 C:\Anaconda3\envs\testenv1

From the --json it is difficult to say if "C:\Anaconda3\envs\issue3\testenv1" should be "issue\testenv1" (note \ is not a invalid character for the name) or "testenv1" or it should not have a name. Each one has its own problem. basename might not be the right thing to use here. conda info --envs --json has more info including root_prefix, which we will need to correctly replicate this. But there are issues with that as well.

Ideally, if conda provides name with --json along with a field that identifies active environments, we could entirely switch to that.

The fix in #11103 addresses the issue at least partially. We will revisit the design of environment detection soon to make it more robust. At that point we are going to look into the various ways to get environments list from conda.

@Qsi1984
Copy link

Qsi1984 commented Apr 16, 2020

Thanks a lot for your clarification.
There is a feature-request for what you need (conda/conda#6797) but doesn't seem to be hight on their priority list ;)
Thanks a lot for your effort.

@karthiknadig
Copy link
Member

This particular issue with long conda env names is addressed, and the fix is in master. It will be available in the May release.

@ghost ghost removed the needs PR label Apr 16, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
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

4 participants