Skip to content

Import on Linux #94

@jcnelson30

Description

@jcnelson30

Hello,

I recently got into PyBind11 as I needed somethings sped up. I develop on my OSX machine and then run long-running processes on my Ubuntu Server.

I'm currently using: pybind11 2.13.6 and cppimport 22.8.2

On OSX, I use the following line to import:

btf_cpp = cppimport.imp_from_filepath(f"{pathlib.Path(
    __file__).parent.resolve()}/cpp/btf.cpp")

Which has no problem finding, building, then importing the module. This 100% works for me on OSX.

The issue I run into, is when I run it on my linux box. I rsync the entire project directory (leaving out the built files). The app pauses during the initial rebuild but then fails import the module as seen below.

  File "/home/bt/tl/btf.py", line 15, in <module>
    btf_cpp = cppimport.imp_from_filepath(f"{pathlib.Path(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dev/lib/python3.12/site-packages/cppimport/__init__.py", line 88, in imp_from_filepath
    load_module(module_data)
  File "/home/miniconda3/envs/dev/lib/python3.12/site-packages/cppimport/importer.py", line 104, in load_module
    _actually_load_module(module_data)
  File "/home/miniconda3/envs/dev/lib/python3.12/site-packages/cppimport/importer.py", line 91, in _actually_load_module
    module_data["module"] = importlib.import_module(module_data["fullname"])
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dev/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'btf'
(dev) me@server:~/bt$ 

I can confirm the package gets built properly on the linux machine as it generates: btf.cpython-312-x86_64-linux-gnu.so next to my cpp file.

I guess I'm not sure how it ultimately registers the built module or how I should go about debugging this further.

Any help would be greatly appreciated. This is a great tool that made the development super convenient. The cpp project I built is only two files so not trying to roll out the cmake carpet for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions