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

Jupyter doesn't work with anaconda #5539

Closed
zohaad opened this issue May 2, 2019 · 15 comments
Closed

Jupyter doesn't work with anaconda #5539

zohaad opened this issue May 2, 2019 · 15 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@zohaad
Copy link

zohaad commented May 2, 2019

Environment data

  • VS Code version: 1.33.1
  • Extension version (available under the Extensions sidebar): 2019.4.2
  • OS and version: macOS Mojave 10.14.3
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.1 Anaconda 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: N/A

Expected behaviour

Jupyter loads correctly

Actual behaviour

it fails to load with anaconda

Steps to reproduce:

  1. select code
  2. shift + enter

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Executing code failed : Error: Activating Python 3.7.1 64-bit ('py37': conda) to run Jupyter failed with Error: Command failed: . /anaconda3/envs/py37/bin/activate && conda activate py37 && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /Users/zohaad/.vscode/extensions/ms-python.python-2019.4.12954/pythonFiles/printEnvVariables.py CommandNotFoundError: 'activate is not a conda command. Did you mean 'source activate'? .

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)

XXX
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label May 2, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 3, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label May 6, 2019
@rchiodo
Copy link

rchiodo commented May 6, 2019

This is not datascience specific. I think the error is we're using '. ' instead of source, although from this
https://github.com/Microsoft/vscode-python/blob/b741e1af6d53cdf94765a6708964d489bd558ff8/src/client/interpreter/activation/service.ts#L105

It looks like it was on purpose.

@DonJayamanne DonJayamanne added feature-interpreter bug Issue identified by VS Code Team member as probable bug labels May 16, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 16, 2019
@aldanor
Copy link

aldanor commented May 18, 2019

@DonJayamanne @rchiodo @xhochy

Building the latest extension version from github master, activation errors still persist with conda.

Basically, before a recent PR (#5516, #4402), I think it was trying to do something like this, which is wrong:

$ <ENV>/activate

Error: activate must be sourced. Run 'source activate envname'
instead of 'activate envname'.

Now it's trying to do something like this (but it's also still wrong!):

$ source <ENV>/bin/activate

Error: no environment provided.

It should be either this:

$ source <ENV>/bin/activate <ENV>

Or, as a matter of fact, conda guys officially suggest using conda activate and conda deactivate instead of sourcing things manually: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment

@aldanor
Copy link

aldanor commented May 18, 2019

The only way I can make it work (and this is on conda/macOS) is replacing the <ENV>/activate script in the environment with this one-liner (where <ENV> is the full absolute path to the environment):

export $PATH=<ENV>/bin:$PATH

Then the Jupyter stuff launches fine (just to verify).

@xhochy
Copy link

xhochy commented May 18, 2019

This is weird. The latest nightly is working for me with conda 4.6. What conda version do you have installed?

@aldanor
Copy link

aldanor commented May 18, 2019

@xhochy conda is 4.6.14, the extension I've just built from the latest master, with a clean install.

Again, seeing what the extension is trying to do - e.g., even jupyter aside, if you select some code and shift-enter, it tries to fire a python console, and prior to that attempts to activate the environment like this: source <ENV>/bin/activate, which doesn't seem right.

@aldanor
Copy link

aldanor commented May 18, 2019

@xhochy If you simply 'run file in the terminal', does it paste source <ENV>/bin/activate there, or something else?

@aldanor
Copy link

aldanor commented May 19, 2019

@xhochy I did a bit more debugging.

Turns out I do indeed have conda 4.6, but that particular environment was created long time ago with an older version of conda (probably 4.5 or, less likely, 4.4 - it's hard to tell). With freshly-created environments the problem doesn't happen.

But this is all very implicit and obscure. IMO either the extension should support a wider range of conda environments, or it should fire an explicit warning saying "please recreate it with a latest conda" (which is not so nice...).

One thing to note: newer conda environments do not even have the <ENV>/bin/activate script at all within the environment. They also don't have conda executable within the environment by default.

With this in mind, if the extension didn't try to source the activate in older conda environments, it would then work for all conda versions? (as in, for all environment versions) I'm still not sure why it's trying to do that, and it sounds more like a bug than a feature.

@willyd
Copy link

willyd commented May 31, 2019

Also experiencing this issue with conda 4.6.14 on Ubuntu 18.04. I believe that conda activate should be used instead of . activate as @aldanor suggested.

@willyd
Copy link

willyd commented May 31, 2019

I changed the .bashrc file from:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

to

export PATH=$PATH:/opt/miniconda3/bin

And everything works as expected.

@nameoverflow
Copy link

nameoverflow commented Jun 22, 2019

The plugin tries to find a conda executable from the same or upper directory of current interpreter (https://github.com/DonJayamanne/pythonVSCode/blob/f590f9c89ae5ee31f33bc66626e9f8279ea17763/src/client/interpreter/locators/services/condaService.ts#L249)
but the conda executable is located in <conda_path>/condabin in current version.
So what the problem with just running conda command from PATH ?

@ghost
Copy link

ghost commented Jul 18, 2019

Maybe this is related: Activating a local conda environment (in ${workspaceFolder}/env) also fails, because conda tries to find a global environment called 'env'. VS Code gives this error:

Executing code failed : Error: Activating Python 3.7.3 64-bit ('env': conda) to run Jupyter failed with 
Error: StdErr from ShellExec, Could not find conda environment: env
You can list all discoverable environments with `conda info --envs`.

I have conda 4.6.14 and VS Code Python Extension 2019.6.24221.

On the other hand, using a local virtual environment created using python -m venv venv works just fine.

@atakanokan
Copy link

What have helped me is to install VS Code from the Anaconda Navigator and starting the application from there. Not sure if it will help you though. (macOS)

This was referenced Sep 17, 2019
@DonJayamanne DonJayamanne mentioned this issue Oct 9, 2019
24 tasks
@gramster gramster added area-environments Features relating to handling interpreter environments and removed feature-interpreter labels Oct 10, 2019
@gramster gramster added this to the FY20Q2 milestone Oct 30, 2019
@DonJayamanne
Copy link

@Arpiiitaaa
Copy link

Arpiiitaaa commented Oct 1, 2021

@luabud may I take this up?

@karrtikr
Copy link

Should be addressed with #15818

@karrtikr karrtikr self-assigned this Oct 20, 2021
@karrtikr karrtikr modified the milestones: FY20Q2, October 2021 Oct 20, 2021
@karrtikr karrtikr added the verified Verification succeeded label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2021
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 verified Verification succeeded
Projects
None yet
Development

No branches or pull requests