简体   繁体   English

Jupyter notebook 找不到模块

[英]Jupyter notebook can not find the module

I am using Jupyter notebook for a project, I have been writing in vs code but recently switched to Jupyter.我正在将 Jupyter notebook 用于一个项目,我一直在用 vs 代码编写,但最近切换到了 Jupyter。 The code was working in vs code but, already installed the modules with pip, but I am getting import error in Jupyter notebook.该代码在 vs 代码中运行,但是已经使用 pip 安装了模块,但是我在 Jupyter 笔记本中遇到了导入错误。 For;为了;

import reverse_geocoder
from geopy.distance import geodesic

I am getting the我得到了

No module named 'reverse_geocoder'
No module named 'geopy'

errors.错误。 How I can install these to Jupyter?我如何将这些安装到 Jupyter?

Google is your friend.谷歌是你的朋友。

You can find a pretty detailed solution here (I strongly suggest you to have a look at it).你可以在这里找到一个非常详细的解决方案(我强烈建议你看看它)。

Anyway, to sum up.总之,总结一下。 I am assuming you wish to install directly from the Jupyter notebook.我假设您希望直接从 Jupyter notebook 安装。 This probably means that you don't have Anaconda (otherwise I'd suggest to install through the Anaconda prompt) but I'll write down the solution also for that case.这可能意味着您没有 Anaconda(否则我建议通过 Anaconda 提示符安装),但我也会针对这种情况写下解决方案。

If you do not have Anaconda then you can simply install it using pip如果你没有 Anaconda,那么你可以简单地使用 pip 安装它

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install reverse_geocoder

If you have Anaconda:如果你有 Anaconda:

# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} reverse_geocoder

However, if you do have Anaconda installed you should simply open the Anaconda prompt and install the package using:但是,如果您确实安装了 Anaconda,您只需打开 Anaconda 提示符并使用以下命令安装软件包:

pip install reverse_geocoder

Yep worked for me .. don't know why, it was installed and ran everywhere else.是的,对我有用.. 不知道为什么,它已安装并在其他任何地方运行。 All good.都好。

Just re-installed at every environment, pip install geopy (Anaconda)刚刚在每个环境重新安装,pip install geopy (Anaconda)

如果您正在使用 Python3 笔记本(在 Python 3.x 环境中运行),请尝试,

pip3 install geopy

I had this problem and it turned out that I simply had the wrong python selected within VS Code.我遇到了这个问题,结果证明我只是在 VS Code 中选择了错误的 python。 You have to select (in the upper right) the python environment corresponding to your project.您必须选择(在右上角)与您的项目对应的 python 环境。

在此处输入图像描述

I have this problem only with Jupyter notebook INSIDE of VS Code.我只有在 VS Code 内部的 Jupyter notebook 才有这个问题。 If I use the actual Jupyter Notebook through my browser, I do not have this problem.如果我通过浏览器使用实际的 Jupyter Notebook,就没有这个问题。

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

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