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 activate is failing when conda is in '/usr/bin/' folder #10902

Closed
junrrein opened this issue Apr 1, 2020 · 21 comments
Closed

Conda activate is failing when conda is in '/usr/bin/' folder #10902

junrrein opened this issue Apr 1, 2020 · 21 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@junrrein
Copy link

junrrein commented Apr 1, 2020

Environment data

  • VS Code version: 1.43.2
  • Extension version (available under the Extensions sidebar): 2020.3.71113
  • OS and version: Fedora 31
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: n/a

Workspace Settings

{
    "python.pythonPath": "/home/julian/.conda/envs/pdi-practica2020/bin/python"
}

Actual behavior

Starting a Jupyter Notebook server fails with error:

Activating Python 3.7.7 64-bit ('pdi-practica2020': conda) to run Jupyter failed with Error: Command failed: . /usr/bin/activate pdi-practica2020 && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/julian/.vscode/extensions/ms-python.python-2020.3.71113/pythonFiles/printEnvVariables.py bash: /usr/bin/activate: No such file or directory .

Expected behavior

The extension should use plain conda activate to activate the conda environment, as the extension does (I think?) when opening a terminal.

Steps to reproduce:

  1. Install conda using the package manager: sudo dnf install conda
  2. Create an environment that includes Jupyter: conda create --name vscode-test notebook
  3. Open a folder with VSCode.
  4. Use the "Select Interpreter" command to activate the vscode-test environment.
  5. Use the "Create New Blank Jupyter Notebook" command.
  6. Add code to the first cell (for example import sys) and run it.

Notes

May be related to #2315 and #7671 and the way they were solved.

@junrrein junrrein added data science feature-request Request for new features or functionality labels Apr 1, 2020
@junrrein junrrein changed the title Launching Jupyter server using conda environment fails because it's trying to use non-existing /usr/bin/activate binary Launching Jupyter server using conda environment fails because it's trying to use non-existing /usr/bin/activate command Apr 1, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Apr 1, 2020
@rchiodo
Copy link

rchiodo commented Apr 1, 2020

Conda activate is not DS specific, removing DS label.

@junrrein
Copy link
Author

junrrein commented Apr 1, 2020

@rchiodo This only fails for the Jupyter Server. Everywhere else the conda environment seems to be applied fine.

@rchiodo
Copy link

rchiodo commented Apr 1, 2020

What does 'Select Interpreter to start Jupyter' show as the current selection? Does it match your python path? And does the selection box indicate it thinks the interpreter is a conda interpreter (the selection box should show something like so for the item you have selected)

image

Those should be all true, but for some reason the code we run doesn't realize that python path is a conda environment.

@junrrein
Copy link
Author

junrrein commented Apr 1, 2020

@rchiodo

What does 'Select Interpreter to start Jupyter' show as the current selection?

Captura de pantalla de 2020-04-01 15-14-35

Does it match your python path?

The one I intend to be selected is the pdi-practica2020: conda one. Even when I select that one, when I use 'Select Interpreter to start Jupyter' the first item in the list is highlighted, and no settings seem to be changed for the workspace.

When using 'Python: Select Interpreter' (not the Jupyter one), here also the first item in the list is the one highlighted, but selecting an interpreter does modify the .vscode/settings.json file in the workspace, and the Python extension does pick up that environment.

@junrrein
Copy link
Author

junrrein commented Apr 1, 2020

@rchiodo

When using 'Select Interpreter to start Jupyter' to select the 'base' environment, where I don't have Jupyter installed, the extension correctly shows me an error about that: Data Science libraries jupyter and notebook are not installed in interpreter Python 3.7.6 64-bit ('base': conda).

When selecting my custom environment, nothing seems to happen, but presumably the extension does see that Jupyter is installed. Just in case, here is my environment.yml file.

@rchiodo
Copy link

rchiodo commented Apr 1, 2020

The 'jupyter' interpreter is not saved in your settings. It's in a different spot. But regardless, it thinks it's a conda environment, so it should be launching it with conda activate. It looks to me like there's a bug somewhere in this code here:
https://github.com/microsoft/vscode-python/blob/master/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts

In the function getUnixCommands it looks like the 'condaFile' is actually found in /usr/bin instead of some conda folder and that's why it's running '/usr/bin/activate'. Perhaps there's a conda in '/usr/bin'?

@junrrein
Copy link
Author

junrrein commented Apr 1, 2020

@rchiodo

There is indeed a conda binary script in my /usr/bin path, and it was installed by my package manager.

Just in case, my bash shell seems to need a plain conda command to use it. Invoking /usr/bin/conda doesn't work:

bash-5.0$ /usr/bin/conda activate pdi-practica2020

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

bash-5.0$ conda activate pdi-practica2020

bash-5.0$ conda env list
# conda environments:
#
pdi-practica2020      *  /home/julian/.conda/envs/pdi-practica2020
base                     /usr

Note: conda init bash was actually used beforehand. It just seems that a direct invocation to /usr/bin/conda doesn't work.

@luabud luabud added the triage label Apr 1, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 1, 2020
@luabud luabud removed the feature-request Request for new features or functionality label Apr 1, 2020
@rchiodo rchiodo changed the title Launching Jupyter server using conda environment fails because it's trying to use non-existing /usr/bin/activate command Conda activate is failing when conda is in '/usr/bin/' folder Apr 1, 2020
@ericsnowcurrently
Copy link
Member

@junrrein, we just published a new release of the extension. Please verify you are still seeing the problem after updating. Thanks!

@ericsnowcurrently ericsnowcurrently added the info-needed Issue requires more information from poster label May 12, 2020
@junrrein
Copy link
Author

@ericsnowcurrently, I'm now using version 2020.5.78807 of the extension.

Unfortunately, I'm still hitting the same issue as in the OP:

Activating Python 3.7.7 64-bit ('pdi-practica2020': conda) to run Jupyter failed with Error: Command failed: . activate pdi-practica2020 && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/julian/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py /home/julian/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/printEnvVariables.py bash: activate: No such file or directory .

@ericsnowcurrently ericsnowcurrently removed the info-needed Issue requires more information from poster label Jun 1, 2020
@Betaglutamate
Copy link

I am having the same issue I think

Command failed: . activate image_env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/betaglutamate/.vscode/extensions/ms-python.python-2020.7.96456/pythonFiles/pyvsc-run-isolated.py /home/betaglutamate/.vscode/extensions/ms-python.python-2020.7.96456/pythonFiles/printEnvVariables.py
bash: activate: No such file or directory

I can use jupyter notebooks using base python and even conda base however it fails with all conda envs.

on further digging i found an issue with conda when creating a new env.

Preparing transaction: done
Verifying transaction: / WARNING conda.core.path_actions:verify(962): Unable to create environments file. Path not writable.
  environment location: /home/betaglutamate/.conda/environments.txt

done
Executing transaction: - WARNING conda.core.envs_manager:register_env(50): Unable to register environment. Path not writable or missing.
  environment location: /home/betaglutamate/anaconda3/envs/test
  registry file: /home/betaglutamate/.conda/environments.txt
done

I think this may be caused by installing conda as su. try uninstalling as here:

https://docs.anaconda.com/anaconda/install/uninstall/

you need to do full uninstall then reinstall without sudo this seems to have fixed my problem.

@junrrein
Copy link
Author

junrrein commented Aug 6, 2020

@Betaglutamate

I think this may be caused by installing conda as su. try uninstalling as here:

https://docs.anaconda.com/anaconda/install/uninstall/

you need to do full uninstall then reinstall without sudo this seems to have fixed my problem.

I have installed conda using my distributions' package manager. Doing a manual 'local' install is undesirable.

@karthiknadig karthiknadig added investigating We are looking into the cause of the issue and removed triage labels Sep 15, 2020
@vrpascuzzi
Copy link

FWIW I'm also having this issue. For some reason, it wants to source an activate script instead of calling conda activate <...>.

@rgranit
Copy link

rgranit commented Oct 19, 2020

I'm having a very similar issue:

Command failed: . /usr/bin/activate env && echo ... bash: /usr/bin/activate: No such file or directory

My conda is in '/usr/bin/conda'

Any suggested solution?

I was able to locate the activate file using find . -name activate and copy it to my working directory.. this solved the issue for me :)

@bw-turner
Copy link

I'm having a similar issue.

I am using VS code on WSL and have installed Miniconda. I have created an environment inside a project directory, and VS Code correctly locates that environment which I can select from the interpreters list.

When I go to open an integrated terminal however, I get:

ben@Firefly:~/Projects/myproj$ source activate /home/ben/Projects/myproj/env
bash: activate: No such file or directory

For some reason source is being called in place of conda.

@brpy
Copy link

brpy commented Jan 3, 2021

Having the same issue.
rgranit's solution fixes the issue for now.

@simozacca
Copy link

I am having the same issue; activation of the environment is using source activate instead of the proper conda activate. I have temporarily fixed it by adding the paths to the conda activate script in my PATH through my .bashrc but this is a very disruptive issue.

@simozacca
Copy link

Issue related to #8770 and #8870

@chadHGY
Copy link

chadHGY commented Feb 5, 2021

Hi recently I also encounter_ similar problem,
then I find that in the latest python-extension(v2021.1.502429) comes with setting that you can manually specify the root of the conda path:

image

After assigning the conda path I can launch the jupyter-notebook normally

@memeplex
Copy link

The above suggestion fixes nothing for me, after setting the conda path to /usr/local/Caskroom/miniconda/base/condabin/, I'm still getting a "source activate ..." line that fails with "no such file or directory" (since the is no such file or directory there, so I'm unable to see how it could fix anything).

@memeplex
Copy link

memeplex commented May 14, 2021

Ok, the problem is that, at least in a brew installation, the conda executable that is in the path after sourcing:

source /usr/local/Caskroom/miniconda/base/etc/profile.d/conda.sh

is in:

/usr/local/Caskroom/miniconda/base/condabin/conda

while activate is in:

/usr/local/Caskroom/miniconda/base/activate

I don't know what is the best approach to fix this (besides manually configuring the path). Probably vscode should do conda activate instead of plain activate, since that's what the conda documentation says.

@karrtikr karrtikr added needs PR Ready to be worked on and removed needs PR Ready to be worked on labels Aug 9, 2022
@karthiknadig karthiknadig added triage-needed Needs assignment to the proper sub-team and removed investigating We are looking into the cause of the issue labels Mar 3, 2023
@karrtikr
Copy link

karrtikr commented May 3, 2023

#11039 should solve this issue. The fix should already be out if you want to try it:

  • Use pre-release:
    image
  • Add "python.experiments.optInto": ["pythonTerminalEnvVarActivation"] to User settings and reload window.
  • Make sure to not be using a multiroot workspace

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2023
@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests