英文:
Jupyter Notebook doesn’t recognise Anaconda installation
问题
由于某种原因,Jupyter不识别Anaconda安装。
import os
result = os.popen('conda list anaconda$').read()
print('\nAnaconda版本:\n', result)
结果:
Anaconda版本:
在C:\Users\Andy\anaconda3环境中的软件包:
名称 版本 构建 频道
我已经更新了Windows路径变量如下:
C:\Users\Andy\anaconda3;
C:\Users\Andy\anaconda3\Scripts
conda.exe应用程序位于Scripts目录中
提前感谢任何帮助
编辑...
运行以下命令后的前10(左右)行:
conda list
结果如下:
C:\Users\Andy\anaconda3环境中的软件包:
注意:您可能需要重新启动内核以使用更新的软件包。
名称 版本 构建 频道
_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
英文:
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
答案1
得分: 1
使用Jupyter,在笔记本中的一个单元格中运行以下内容:
%%capture out
%conda list anaconda$
(这将将%conda list
的结果发送到out
,其类型为IPython.utils.capture.CapturedIO
。您可以在这里的IPython.utils.capture.CapturedIO
文档中了解如何访问其各种属性。下面我将介绍如何处理它并解析出您想要的版本信息。)
然后,在下一个单元格中,您可以解析收集到的信息:
out.stdout.split("Channel")[1].split("anaconda", 1)[1].split()[0]
根据您在上面的评论中发布的内容,您应该看到:
2023.07
当我运行它时,我实际上看到的是2022.05
。
您最初发布的尝试os.popen('conda list anaconda$').read()
是通过os
将您的命令发送到临时系统 shell,因此可能不在运行Jupyter的内核所在的确切环境中。%conda list
使用魔术命令确保在运行Jupyter的内核所在的相同环境中运行。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论