为什么我无法从jupyter笔记本中导入多重速率?
我正在尝试从使用Pycharm配置的VENV环境中运行Jupyter笔记本。但是,当我尝试从Jupyter笔记本运行代码时,我会在尝试导入模块时会遇到以下
import multipledispatch
ModuleNotFoundError: No module named 'multipledispatch'
错误任何问题。
当我从内检查已安装的软件包列表时,使用
python -m pip list
该模块的笔记本按预期出现。如果我尝试从笔记本中安装模块,
!python -m pip install multipledispatch
请告诉我已经满足了要求,但是,我仍然无法导入模块。
我能够导入创建VirtualEnv后安装的其他非标准模块,因此似乎仅限于多重ISPATCH模块。有人有任何想法可能导致这一问题或如何修复它吗?
I'm trying to run a jupyter notebook from within a venv environment configured using PyCharm. However, when I try to run the code from the jupyter notebook I'm getting the following error when trying to import a module I know to exist
import multipledispatch
ModuleNotFoundError: No module named 'multipledispatch'
If I open a terminal, activate the virtual environment and run the code manually in Python it works without any problems.
When I check the list of installed packages from within the notebook using
python -m pip list
the module appears as expected. If I try to install the module from within the notebook using
!python -m pip install multipledispatch
it tells me that requirements are already satisfied, however, I'm still unable to import the module.
I'm able to import other non-standard modules which I installed after creating the virtualenv, so this appears to be limited to the multipledispatch module. Does anyone have any ideas what might be causing this or how it might be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我弄清楚了这件事。即使我将python内核设置为基本项目中的 venv ,但 site-packages 目录目录均未添加到python路径中。
如下
i通过手动向项目和pip添加路径( site-packages *目录在笔记本开始时。 >将其与笔记本电脑相同
目录
的
pip_path
值为我可以在笔记本上运行的虚拟机的站点包装目录的位置。根。在每个笔记本的开头我添加了以下内容
I figured out what's happening with this. Even though I'd set the python kernel to use the venv from the base project, the site-packages directory wasn't being added to the Python path.
My directory structure was as follows
I fixed this by manually adding the path to the project and the pip (site-packages* directory at the beginning of the notebook. I created a file called project_path.py and placed it in the same directory as the notebook.
The
os.pardir
reference allows me to add the projectDir to the notebook's path, this ensures that my custom packages can be called from within the notebook.The
pip_path
value gives me the location of the site-packages directory for the virtual machine in which the notebook runs. By adding both of these to the python path I can import packages in my notebooks just as I can in the root dir.At the beginning of each notebook I added the following to run the code and fix up the paths