简体   繁体   English

pybind11 模块在 Jupyter 中找不到,但可以在命令行 python 和 Spyder 中找到

[英]pybind11 module cannot be found in Jupyter, but can be found in command line python and Spyder

Folks, I am having this puzzle with a pybind11 library mytest.cp37-win_amd64.pyd put in C:\Temp.伙计们,我在 C:\Temp 中使用 pybind11 库 mytest.cp37-win_amd64.pyd 遇到了这个难题。 Then I have this:然后我有这个:

import sys
sys.path.insert(0, r"C:\Temp")
from mytest import *

Now here comes the problem, if I launch the python in command line:现在问题来了,如果我在命令行中启动 python:

>python
>>>import sys
>>>sys.path.insert(0, r"C:\Temp")
>>>from mytest import *

It works fine.它工作正常。 Or I just put above code in test.py, then run:或者我只是将上面的代码放在 test.py 中,然后运行:

>python test.py

It also works.它也有效。 If I put this piece of code in Spyder, it works as well.如果我将这段代码放在 Spyder 中,它也可以工作。 But if I put this piece of code in Jupyter, it will not work by saying: ModuleNotFoundError: No module named 'mytest'但是如果我把这段代码放在 Jupyter 中,它不会说: ModuleNotFoundError: No module named 'mytest'

I am sure all my tests are conducted in the same python environment by printing it out:我确信我所有的测试都是在同一个 python 环境中通过打印出来的:

import os
print(os.environ['CONDA_DEFAULT_ENV'])

Am I missing anything here?我在这里错过了什么吗?

With Wayne's help and a previous post , I finally found out the root cause, that is the version of the python running in the Jupyter kernel is different from that of the environment from which the Jupyter is launch and also the pybind11 library is build with.在 Wayne 的帮助和之前的一篇文章中,我终于找到了根本原因,即 Jupyter 内核中运行的 python 版本与启动 Jupyter 的环境以及构建 pybind11 库的环境不同。 After I reinstall the Jupyter in the environment again, the library is picked up successfully.在我重新在环境中重新安装 Jupyter 后,该库被成功拾取。

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

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