简体   繁体   English

无法在 jupyter notebook 中导入已安装的软件包

[英]Can't import installed packages in jupyter notebook

If I run the following in a Jupyter notebook :如果我在 Jupyter 笔记本中运行以下命令:

!pip install gTTS

from gtts import gTTS 

I get the following output:我得到以下输出:

Requirement already satisfied: gTTS in c:\users\username\.conda\envs\gpu\lib\site-packages (2.0.4)
Requirement already satisfied: click in c:\users\username\.conda\envs\gpu\lib\site-packages (from gTTS) (7.0)
Requirement already satisfied: six in c:\users\username\.conda\envs\gpu\lib\site-packages (from gTTS) (1.13.0)
Requirement already satisfied: gtts-token>=1.1.3 in c:\users\username\.conda\envs\gpu\lib\site-packages (from gTTS) (1.1.3)
Requirement already satisfied: requests in c:\users\username\.conda\envs\gpu\lib\site-packages (from gTTS) (2.22.0)
Requirement already satisfied: beautifulsoup4 in c:\users\username\.conda\envs\gpu\lib\site-packages (from gTTS) (4.8.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\username\.conda\envs\gpu\lib\site-packages (from requests->gTTS) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\username\.conda\envs\gpu\lib\site-packages (from requests->gTTS) (2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\username\.conda\envs\gpu\lib\site-packages (from requests->gTTS) (1.25.7)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\username\.conda\envs\gpu\lib\site-packages (from requests->gTTS) (2.8)
Requirement already satisfied: soupsieve>=1.2 in c:\users\username\.conda\envs\gpu\lib\site-packages (from beautifulsoup4->gTTS) (1.9.5)


ModuleNotFoundError: No module named 'gtts'

What should I do?我该怎么办?

Edit: from gtts import gTTS works perfectly fine in the terminal.编辑: from gtts import gTTS在终端中运行良好。

Update:更新:

TL;DR: Still facing this problem TL;DR:仍然面临这个问题

Even after 5 months I haven't been able to narrow down what the problem is.即使在 5 个月之后,我也无法缩小问题的范围。 The answers below are workarounds but don't actually address the main problem.下面的答案是解决方法,但实际上并未解决主要问题。 Why is this happening?为什么会这样? And jupyter notebook isn't the only tool where I am facing this issue. jupyter notebook并不是我面临这个问题的唯一工具。 This is a similar question I asked titled "VSCode terminal doesn't activate conda environment".这是我问的一个类似的问题,标题为“VSCode 终端不激活 conda 环境”。 Similarly with Sublime text.与 Sublime 文本类似。 I can't set up the internal console to build from environments.我无法设置内部控制台以从环境中构建。

try:尝试:

!conda install gTTS
from gtts import gTTS 

Because you are using Conda, conda should be used instead of pip因为您使用的是 Conda,所以应该使用 conda 而不是 pip

pip install version to your default python version which is python2, you should do pip 安装版本到你的默认 python 版本,即 python2,你应该这样做

!python3 -m pip install gTTS
from gtts import gTTs

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

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