Search code examples
pythonmodulejupyter-notebookpybind11modulenotfounderror

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. 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
>>>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:

>python test.py

It also works. If I put this piece of code in Spyder, it works as well. But if I put this piece of code in Jupyter, it will not work by saying: ModuleNotFoundError: No module named 'mytest'

I am sure all my tests are conducted in the same python environment by printing it out:

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

Am I missing anything here?


Solution

  • 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. After I reinstall the Jupyter in the environment again, the library is picked up successfully.