Search code examples
pythonjupyter-notebookanaconda3

Jupyter Notebook doesn’t recognise Anaconda installation


For some reason Jupyter won't recognise the Anaconda installation

import os
result = os.popen('conda list anaconda$').read()
print('\nAnaconda Version:\n', result)

Result:

Anaconda Version: packages in environment at C:\Users\Andy\anaconda3:

Name Version Build Channel

I've updated the Windows Path variables as follows

C:\Users\Andy\anaconda3; C:\Users\Andy\anaconda3\Scripts

The conda.exe application is in the Scripts directory

Thanks in advance for any help

Edit...

The top 10(ish) rows from running

conda list

are

# packages in environment at C:\Users\Andy\anaconda3:
Note: you may need to restart the kernel to use updated packages.

#
# Name                    Version                   Build  Channel
_anaconda_depends         2023.07                 py311_0  
abseil-cpp                20211102.0           hd77b12b_0  
aiobotocore               2.4.2           py311haa95532_0  
aiofiles                  22.1.0          py311haa95532_0  
aiohttp                   3.8.3           py311h2bbff1b_0  
aioitertools              0.7.1              pyhd3eb1b0_0  
aiosignal                 1.2.0              pyhd3eb1b0_0  
aiosqlite                 0.18.0          py311haa95532_0  
alabaster                 0.7.12             pyhd3eb1b0_0  
anaconda-catalogs         0.2.0           py311haa95532_0  
anaconda-client           1.11.3          py311haa95532_0  
anaconda-navigator        2.4.2           py311haa95532_0  
anaconda-project          0.11.1          py311haa95532_0  

Solution

  • Using Jupyter, run in a cell in your notebook the following:

    %%capture out
    %conda list anaconda$
    

    (That sends the result of the %conda list to out, which is of the type IPython.utils.capture.CapturedIO. You can read about accessing the various attributes of that here in the IPython.utils.capture.CapturedIO documentation. I cover here how I handle it and parse out the version information I think you want next.)

    Then in the next cell, you can parse collected the information:

    out.stdout.split("Channel")[1].split("anaconda",1)[1].split()[0]
    

    Based on what you posted in a comment above, you should see:

    2023.07
    

    I actually see 2022.05 when I run it.


    Your original posted attempt os.popen('conda list anaconda$').read() is sending your command to a temporary system shell via os, and so that may not be in the exact environment where you notebook kernel is running. %conda list uses the magic command to insure things run in the same environment where your kernel backing Jupyter runs.