简体   繁体   English

如何获得 Jupyter Notebook 以查看其打开环境中的模块?

[英]How can I get a Jupyter Notebook to see the modules in the environment that it was opened in?

I am attempting to import cartopy into a notebook but am running into issues.我正在尝试将 cartopy 导入笔记本,但遇到了问题。 If I do a "conda install cartopy" in my base environment, I get the frozen/flexible solve issue ( https://github.com/conda/conda/issues/9367 ).如果我在我的基本环境中执行“conda install cartopy”,我会遇到冻结/灵活解决问题( https://github.com/conda/conda/issues/9367 )。 When I open a new environment and do a "conda install cartopy", it seems like everything works.当我打开一个新环境并执行“conda install cartopy”时,似乎一切正常。 "conda list" shows version 0.18.0 in that environment. “conda list”在该环境中显示版本 0.18.0。 Then I open a Jupyter Notebook from within that environment and try to import it into the notebook but originally got the response "no module named cartopy".然后我从该环境中打开一个 Jupyter Notebook 并尝试将其导入笔记本,但最初得到响应“没有名为 cartopy 的模块”。 I tried fiddling with my environments and settings based on feedback on this page ( In which conda environment is Jupyter executing? ), but now the error is "no module named numpy"!我尝试根据此页面上的反馈摆弄我的环境和设置( Jupyter 在哪个 conda 环境中执行? ),但现在错误是“没有名为 numpy 的模块”! Can someone please help me understand why the notebook isn't seeing these modules?有人可以帮我理解为什么笔记本没有看到这些模块吗? Thank you.谢谢你。

Are you certain that numpy is installed in this new environment?您确定在这个新环境中安装了numpy吗?

Given that you are using the Anaconda distribution of Python, you should be able to view/configure your environment and it's installed modules using the Anaconda Navigator.鉴于您使用的是 Python 的 Anaconda 发行版,您应该能够使用 Anaconda Navigator 查看/配置您的环境及其安装的模块。 Here you can see a full list of all installed modules, and via the terminal/console, launch a Jupyter Notebook from not only within a specific environment, but within a specific directory!在这里,您可以看到所有已安装模块的完整列表,并通过终端/控制台不仅在特定环境中,而且在特定目录中启动 Jupyter Notebook!

从特定环境打开终端

On the left hand side, you can choose the environment that you want to use to start Jupyter Notebook, and on the right you can view all of the installed modules in that environment.在左侧,您可以选择要用于启动 Jupyter Notebook 的环境,在右侧,您可以查看该环境中所有已安装的模块。 Make sure that jupyter , numpy , and cartopy are all listed as installed packages.确保jupyternumpycartopy都列为已安装的软件包。

To make sure that I am launching Jupyter from my desired environment, I always launch it directly from the terminal.为了确保我从我想要的环境启动 Jupyter,我总是直接从终端启动它。 I "Open Terminal" with my environment, "cd" into the directory that I want to use, and then use the jupyter notebook or jupyter lab command.我在我的环境中“打开终端”,“cd”到我要使用的目录中,然后使用jupyter notebookjupyter lab命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM