1

EDIT: Problem solved.

Turns out Avast was classifying python.exe within the environments as a virus due to fresh conda installs (and being in silent mode I never found out). Solution found from here: https://github.com/ContinuumIO/anaconda-issues/issues/8266

__

I have something of a problem which I haven't seen anyone else directly have with conda environments and python kernels.

I can successfully create environments and install packages in them etc., but everytime I try to either (i) start a jupyter notebook or (ii) otherwise call an environment kernel in e.g. the VS Code jupyter extension, the kernel environment kernel "disappears" entirely from the environment in question.

In the former jupyter case, the environment successfully launches the notebook browser window when calling "jupyter-notebook" for the first time, but after some 5-10 seconds the browser dies and gives a connection error (I allowed my browser through firewalls etc. which hasn't helped). Trying to call the notebook again from the command line results in an "Unable to create process using 'C:\Users\user\miniconda3\envs\envname\python.exe C:\Users\user\miniconda3\envs\envname\Scripts\jupyter-notebook-script.py' error, after which calling "where python" on the command line only returns the base kernel, and loses all connection to the environment kernel.

In the VS Code case using the jupyter extension, I correctly get prompted to choose a python interpreter and successfully manage again to execute cells for about 5-10 seconds, until VS Code returns an "Error: Direct kernel connection broken" after which again the kernel just completely vanishes from both the command line and the kernel menu in VS Code.

No files in the environments seem to have changed (AFAIK) and I am completely baffled as to what is going on.

Throughout all of these the base kernel seems to run fine, so I'd venture a guess this has something to do with the way jupyter calls the environment kernel and somehow breaks them in the process. I was successfully running a number of environments for months before on the same setup. The problem initially occurred when I created a new environment, launched VS Code for that environment which inadvertently did not have ipykernel installed, and after getting a prompt from VS Code asking me to install ipykernel, every pre-existing environment consistently started failing in the way described above. After this I reinstalled Anaconda and I have been unable to get a single environment to work.

A minimal example of how the environments were typically created:

conda create --name envname_1 python=3.7

and in testing and installing some packages with conda I cloned the base environment a number of times to sequentially test whether the kernel keeps failing with

conda create --name envname_2 --clone envname_1

and so on. Regardless of the environment the problem persists. After activating the environment with

conda activate envname

asking "where python" within the environment initially correctly returns

C:\Users\user\miniconda3\envs\envname\python.exe
C:\Users\user\miniconda3\python.exe

and after calling the kernel in some jupyter-context and having it fail, "where python" from the command line returns just

C:\Users\user\miniconda3\python.exe

I am running on Windows 10 Home 64-bit (version 2004, OS build 19041.867), miniconda3 4.9.2 with base environment python 3.8.5 (the environment kernels tested have mainly been 3.7.x, but 3.8.x has not made a difference so far in testing). Miniconda is installed in my C:\Users\user\miniconda3 directory. (I'm not sure what other details would be helpful here).

So far I've tried:

  1. Purging everything conda-related or python-related from my computer as completely as possible, by using 1) anaconda-clean and then removing the "envs" and "pkgs" folders separately before running the uninstall from standard conda. Miniconda is just the latest n-th reinstall after which the same issues persist.

  2. Setting up a number of test environments in different ways and sequentially testing where the error occurs - seems to always be when activating the kernel one way or another

  3. Removing all possibly related path variables prior to reinstalling

  4. Removing all other python versions (which correctly started pointing python to the base environment - before this an additional problem was the each environment on the command line was attempting to point to my global python installation instead of either the base or environment kernels - this might be somehow related to what is going on here)

  5. Trying all kinds of other little things related to jupyter-notebooks losing kernels within the notebooks, but mostly those have not been applicable since I cannot even use the command line after calling the kernel to work once.

  6. Verified at each step when creating new environments that the environment kernel is correctly pointed to in the environment until calling it from jupyter or VS Code (+ jupyter lab seems to have the same outcome)

I'm a humble man and don't ask for much, would just like to keep working with isolated environments in the future as well. I'm not exactly a whiz when it comes to these things so I'm unsure where else I should be looking or what else I should be trying. Am starting to lose hope as I've been trying to figure this out for a good week now with nothing to show for it.

I hope I'm just being an idiot and overlooking something simple and obvious here since I've not managed to find any similar issues having been resolved. Regardless, any ideas on where I might look to next would be invaluable!

Huug.
  • 177
  • 12
  • This is quite exhaustive. A few thoughts. 1. Aside from the kernel and jupyter notebook issues, have you checked to see if the environment works for other purposes? For example, like activating it and running a script with a specific package/library that is only available for that conda environment. This could help diagnose whether it's just a ipykernel issue or the entire conda environment. 2. Have you tried the full Anaconda instead of miniconda? Would also be curious if 3.9 is also an issue. – astrochun Mar 21 '21 at 16:41
  • Thank you so much for your comment! 1. No I had not, but just did. Works fine with "arrow" in the environment and the python interpreter finds the correct version pf python (3.7.10) within the environment as well, so seems to be working fine until called externally. 2. Yes I have, initially I had the standard installation but after several reinstalls, I thought that the clutter in the standard installation might be partly the culprit. Any ideas come to mind from having the kernel work in the interpreter directly? Seems it must have something to do with the way jupyter kernels get called. – Huug. Mar 21 '21 at 17:41
  • Below is the little test script I performed to check this: 'Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 15:37:01) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import arrow >>> utc = arrow.utcnow() >>> utc >>> utc = utc.shift(hours=1) >>> utc >>> local = utc.to('GMT+2') >>> local >>> local.timestamp() 1616352044.119187' – Huug. Mar 21 '21 at 17:46

0 Answers0