Skip to content

opening jupyter notebook tries to activate wrong env #14902

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
montythepython opened this issue Dec 5, 2020 · 6 comments
Closed

opening jupyter notebook tries to activate wrong env #14902

montythepython opened this issue Dec 5, 2020 · 6 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@montythepython
Copy link

Environment data

  • VS Code version: 1.51.1
  • Jupyter Extension version (available under the Extensions sidebar): v2020.11.399
  • Python Extension version (available under the Extensions sidebar): v2020.11.371526539
  • OS (Windows | Mac | Linux distro) and version: Mint 20 Ulyana
  • Python and/or Anaconda version: Conda 4.9.0 (global python 3.8.5)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Jupyter server running: Local

Expected behaviour

To be able to run python code in a jupyter notebook inside of VS Code using the jupyter extension

Actual behaviour

When I open a notebook inside of VS Code (and everyime I try to run code inside), I get this:

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

After attempting that for the first time, everytime I open the integrated terminal in VS Coded, it tries to do this:

source activate /home/arthur/Documents/sqliteTest/env

and I right after:

bash: activate: No such file or directory

The path to the env is correct. It also seems to be running the right Python Interpreter: ./env/bin/python3.7

If I just change the word "source" for "conda":

conda activate /home/arthur/Documents/sqliteTest/env

the env activates without a problem but if I try to run code from my notebook inside VS Code, I get the same result:

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

If I activate the env and then type jupyter notebook, I can see it on my localhost and all works fine

Steps to reproduce:

  1. Open VS Code,
  2. open a .ipynb file
  3. Also problem replicates everytime I run code inside the notebook in VS Code.

Logs

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - control'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'DeprecatePythonPath - control'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaa'

conda --version
pyenv root
python3.7 ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python3.6 ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python3 ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python2 ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
conda info --json
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
conda env list
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
python ~/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
pyenv root
pyenv root
pyenv root
conda info --json
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
conda env list
Error 2020-12-05 21:58:04: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file '/home/arthur/Documents/sqliteTest/.vscode/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/home/arthur/Documents/sqliteTest/.vscode/settings.json')
at _handleError (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:730:838)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async y.readText (/home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/out/client/extension.js:9:152841)
at async p.doesFileNeedToBeFixed (/home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/out/client/extension.js:39:469606)
at async /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/out/client/extension.js:39:468733
at async Promise.all (index 1)
at async p.getFilesToBeFixed (/home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/out/client/extension.js:39:468679)
at async p.updateTestSettings (/home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/out/client/extension.js:39:468306)] {
code: 'FileNotFound',
name: 'EntryNotFound (FileSystemError)'
}
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
Error 2020-12-05 21:58:04: getActivatedEnvironmentVariables [Error: Command failed: . activate /home/arthur/Documents/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py
bash: activate: No such file or directory

at ChildProcess.exithandler (child_process.js:304:12)
at ChildProcess.emit (events.js:223:5)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:430:11)
at Socket.emit (events.js:223:5)
at Pipe.<anonymous> (net.js:664:12)] {

killed: false,
code: 1,
signal: null,
cmd: ". activate /home/arthur/Documents/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py"
}
Error 2020-12-05 21:58:04: getActivatedEnvironmentVariables, Class name = P, completed in 661ms, has a falsy return value, Arg 1: undefined, Arg 2: {"architecture":3,"path":"/home/arthur/Documents/sqliteTest/env/bin/python","version":{"options":{"loose":false,"includePrerelease":false},"loose":false,"raw":"3.7.8-final","major":3,"minor":7,"patch":8,"prerelease":["final"],"build":[],"version":"3.7.8-final"},"sysVersion":"3.7.8 | packaged by conda-forge | (default, Nov 27 2020, 19:24:58) \n[GCC 9.3.0]","sysPrefix":"/home/arthur/Documents/Dev/codecademy_data_science/sqliteTest/env","fileHash":"bb92ae2f6b688b7455e48aed14639ad25c9cf4153ae644aa92ad57f3ee5b2ebb622209bd4105923dbf5f8266c7ec961d65c0a105d09d1a7237d9958d3ffd59bc","companyDisplayName":"Anaconda, Inc.","envType":"Conda","envPath":"/home/arthur/Documents/sqliteTest/env","envName":"","displayName":"Python 3.7.8 64-bit (conda)"}, Arg 3: true [Error: Command failed: . activate /home/arthur/Documents/Dev/codecademy_data_science/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py
bash: activate: No such file or directory

at ChildProcess.exithandler (child_process.js:304:12)
at ChildProcess.emit (events.js:223:5)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:430:11)
at Socket.emit (events.js:223:5)
at Pipe.<anonymous> (net.js:664:12)] {

killed: false,
code: 1,
signal: null,
cmd: ". activate /home/arthur/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py",
vslsStack: [
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {},
CallSite {}
]
}

pyenv root
Python interpreter path: ./env/bin/python3.7
Starting Jedi Python language engine.
pyenv root
Starting Jedi Python language engine.
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root
pyenv root

@montythepython
Copy link
Author

I forgot to mention it was working well before. I updated VS Code and installed two Docker extensions before I realized I had the problem.
I am not sure it is because of the update or extensions but those are things that happened in between having it working and realizing it was no longer working.

@joyceerhl
Copy link

The Jupyter extension relies on the Python extension to retrieve activated environment variables for the selected interpreter, we don't compute that ourselves. In this case it seems like the the activation command is not being correctly computed. The code for that is here:

const command = `${activationCommand} && echo '${getEnvironmentPrefix}' && python ${args.join(' ')}`;

@joyceerhl joyceerhl transferred this issue from microsoft/vscode-jupyter Dec 7, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Dec 7, 2020
@montythepython
Copy link
Author

Thank you,

I took a look at what you showed me. Yes, I can see all that is happening but I dont know how to fix it. This is what I see happening:
here:

const activationCommands = await this.helper.getEnvironmentActivationShellCommands(

the value 'source' is passed to const activationCommands

here, the value 'source' gets transformed into a 'dot' (" . "):

protected fixActivationCommands(commands: string[]): string[] {

later, when this line executes:

const command = `${activationCommand} && echo '${getEnvironmentPrefix}' && python ${args.join(' ')}`;

I can see this in the jupyter terminal output:
. /home/arthur/Documents/Dev/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py

vs code pops this message:
Command failed: . activate /home/arthur/Documents/Dev/sqliteTest/env && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/pyvsc-run-isolated.py /home/arthur/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py bash: activate: No such file or directory

These two messages differ in that one shows the word 'activate' after the "dot"
I am not sure why or if it means something but I dont get it.

In any case neither way will activate the env.

If the function 'getEnvironmentActivationShellCommands' in line 156 wouldnt pass 'source' as a value, it wouldnt get replaced by the "dot" and perhaps the command wouldnt fail.

Not sure if that is a solution. If it is, what would be the next step? I dont know where that file is in my computer. I cannot find it anywhere.

Thank you!

@luabud luabud added the triage label Dec 7, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Dec 7, 2020
@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug area-environments Features relating to handling interpreter environments labels Dec 7, 2020
@karrtikr
Copy link

karrtikr commented Dec 7, 2020

Hey @montythepython 👋 Your issue seems very similar to #14123.
Looks like the activation command failed for you. conda activate is the best way to do this on new versions of conda (we plan to eventually change to this), but source activate should also work provided that it's done in the right directory - and . activate is a shorthand for that.

I think it might be that you don't have the conda bin directory in PATH, and so bash can't find the activate script. Where is conda installed? Can you try adding <installation_directory>/bin to PATH (or wherever the bin directory is) and see if it works?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Dec 7, 2020
@montythepython
Copy link
Author

hi @karrtikr!

Thank you for the link! it solved the problem. In my case I only had to uncheck:

image

Everything was working before, so somehow that got globally checked and things stopped working. maybe after updating VS Code.

@karthiknadig (thanks for your post!) recommends to change this setting ideally only for the project and not for the VS Code "User". I have the same problem with every project so I guess in my case it would be better to uncheck for User.

Thank you!

@karrtikr
Copy link

karrtikr commented Dec 7, 2020

Alright, #14902 (comment) is still helpful in case you need to check it for user settings as well. Closing this.

@karrtikr karrtikr closed this as completed Dec 7, 2020
@ghost ghost removed the triage label Dec 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 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 info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants