我已经安装了 fuzzywuzzy 模块,并且当我将其导入到 jupyter 笔记本中时,我可以在 python shell 中导入它,但会出现错误“找不到模块”。
>>> from fuzzywuzzy import fuzz
>>>'''
```import pandas as pd
import json
from fuzzywuzzy import fuzz```
```ModuleNotFoundError
Traceback (most recent call last)
<ipython-input-2-a67086b59a14> in <module>
1 import pandas as pd
2 import json
---> 3 from fuzzywuzzy import fuzz
ModuleNotFoundError: No module named 'fuzzywuzzy'```
这个错误经常发生。我建议使用虚拟环境,然后执行
pip install fuzzywuzzy
这是最理想、最可靠的防火解决方案。以下是使用 venv 创建和激活虚拟环境的说明:
1)克隆存储库后,
cd
进入存储库并运行命令:python3 -m venv venv
This will create the virtual environment. Make sure to name it venv because the .gitignore file
has been initialized to ignore it by default.
2) 通过运行以下命令激活虚拟环境:
source venv/bin/activate
3)您可以随时运行
deactivate
离开虚拟环境。
1)克隆存储库后,
cd
进入存储库并运行命令:python -m venv venv
This will create the virtual environment. Make sure to name it venv because the .gitignore file
has been initialized to ignore it by default.
2) 通过运行以下命令激活虚拟环境:
venv\Scripts\activate.bat
To activate the virtual environment inside of a code editor's bash, run: venv\Scripts\activate.ps1
3)您可以随时运行
deactivate
离开虚拟环境。
比较 shell 与笔记本中的 sys.executable 和 sys.path。你是 运行相同的解释器,具有相同的站点包位置? – 阿马丹 2019 年 7 月 17 日 5:32
这就是我的答案!我已从 shell 复制了
sys.path
结果以在笔记本中分配 sys.path
,如下所示:
sys.path = ['list-of-paths-from-my-shell']
然后,就解决了!
宾果游戏。
您需要通过 Anaconda 提示符安装