简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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