ImportError: Error importing numpy: you should not try to import numpy from its source directory #5265
Replies: 1 comment
-
I got the same thing. I've built with To fix it (for me):
set_property(TARGET prog APPEND PROPERTY BUILD_RPATH "$ORIGIN")
set_property(TARGET prog APPEND PROPERTY INSTALL_RPATH "$ORIGIN")
I suspect somehow setting the runtime search path to ignore the vcpkg-built --edited to add-- set_property(TARGET prog PROPERTY SKIP_BUILD_RPATH TRUE)
target_link_options(prog PRIVATE -Wl,-rpath,\$ORIGIN)
set_property(TARGET prog APPEND PROPERTY INSTALL_RPATH "$ORIGIN") --edited to add-- Maybe best solution:Doing the following (setting various values prior to set(My_Python_Version "3.11")
set(Python_EXECUTABLE "/usr/bin/python${My_Python_Version}")
set(Python_INCLUDE_DIR "/usr/include/python${My_Python_Version}")
set(Python_LIBRARY "/usr/lib/x86_64-linux-gnu/libpython${My_Python_Version}.so")
execute_process(COMMAND ${Python_EXECUTABLE} -c "import numpy;print(numpy.get_include())" OUTPUT_VARIABLE Python_NumPy_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
find_package(Python ${My_Python_Version} EXACT COMPONENTS Interpreter Development NumPy REQUIRED) but this may be pretty specific to Ubuntu (the only thing I've run on). |
Beta Was this translation helpful? Give feedback.
-
I'm working from within an embedded environment.
When trying to run the following code;
I receive the traceback:
I've tried installing, uninstalling, using different site-packages paths, etc, etc, but all to no avail.
Numpy works fine with imported in a shell or running a script, but in the embedded context, its a no go.
Beta Was this translation helpful? Give feedback.
All reactions