Jetson_inference build in venv uses wrong site-pacakages during make install

I need to use jetson_inference and jetson_utils in a python 3.7 environment on my Jetson Nano. I created a virtual environment that has python3.7 as the default python3 and I rebuilt various packages from source (OpenCV, NumPy, etc). and installed them. They seem to work fine and I can import them from a python3.7 (also works when I call python3, which points to python3.7 in my virtual environment).

When I build jetson_inference I see the following in the output, which is as expected"

-- trying to build Python bindings for Python versions:  2.7;3.7
-- detecting Python 2.7...
-- found Python version:  2.7 (2.7.17)
-- found Python include:  /usr/include/python2.7
-- found Python library:  /usr/lib/aarch64-linux-gnu/libpython2.7.so
-- CMake module path:  /home/marc/venvirons/p37test/jetson-inference/utils/cuda;/home/marc/venvirons/p37test/jetson-inference/python/bindings;/home/marc/venvirons/p37test/jetson-inference/python/bindings/../../utils/python/bindings
-- NumPy ver. 1.13.3 found (include: /usr/lib/python2.7/dist-packages/numpy/core/include)
-- found NumPy version:  1.13.3
-- found NumPy include:  /usr/lib/python2.7/dist-packages/numpy/core/include
-- detecting Python 3.7...
-- found Python version:  3.7 (3.7.5)
-- found Python include:  /usr/include/python3.7m
-- found Python library:  /usr/lib/aarch64-linux-gnu/libpython3.7m.so
-- CMake module path:  /home/marc/venvirons/p37test/jetson-inference/utils/cuda;/home/marc/venvirons/p37test/jetson-inference/python/bindings;/home/marc/venvirons/p37test/jetson-inference/python/bindings/../../utils/python/bindings
-- NumPy ver. 1.20.3 found (include: /home/marc/venvirons/p37test/venv/lib/python3.7/site-packages/numpy/core/include)
-- found NumPy version:  1.20.3
-- found NumPy include:  /home/marc/venvirons/p37test/venv/lib/python3.7/site-packages/numpy/core/include

As you can see, it finds NumPy 1.20.3 in the virtual env’s site-packages folder and all is well. However, when I do sudo make install I see the following errors in the output:

-- trying to build Python bindings for Python versions:  2.7;3.7
-- detecting Python 2.7...
-- found Python version:  2.7 (2.7.17)
-- found Python include:  /usr/include/python2.7
-- found Python library:  /usr/lib/aarch64-linux-gnu/libpython2.7.so
-- CMake module path:  /home/marc/venvirons/p37test/jetson-inference/utils/cuda;/home/marc/venvirons/p37test/jetson-inference/utils/python/bindings
-- NumPy ver. 1.13.3 found (include: /usr/lib/python2.7/dist-packages/numpy/core/include)
-- found NumPy version:  1.13.3
-- found NumPy include:  /usr/lib/python2.7/dist-packages/numpy/core/include
-- detecting Python 3.7...
-- found Python version:  3.7 (3.7.5)
-- found Python include:  /usr/include/python3.7m
-- found Python library:  /usr/lib/aarch64-linux-gnu/libpython3.7m.so
-- CMake module path:  /home/marc/venvirons/p37test/jetson-inference/utils/cuda;/home/marc/venvirons/p37test/jetson-inference/utils/python/bindings
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module>
    from . import multiarray
ImportError: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

-- NumPy not found

It appears to be using the /usr/lib/python3 folder for installed packages instead of /home/marc/venvirons/p37test/venv/lib/python3.7/site-packages.

Does anyone know how to get around this? Is there an argument I can pass to make install to force it to use the desired path? Is it a CMake arg I need to use?

Thanks in advance!

@mjasner it would seem to be a difference of running with sudo versus not, and normally that part doesn’t get run under sudo make install if you do cmake ../ && make first. Have you already done that, or can you try that first?

I’ve not built/used jetson-inference in a virtual environment before (typically I use containers instead) so you may encounter some hiccups like that. You may also need to modify the Python module install paths here:

Ah, that makes sense. I already did “cake…/” and “make -j3” (I use 3 instead of 4 because I run the jetson headless and this leaves one core open to process remote connections for status checks).

Without sudo, though, the install complains about permissions issues, so I guess I’ll need to modify those files you mentioned.

Thanks

Hmm okay, I’m not sure why but cmake must be re-running those configuration steps during make install even though you already ran make, and under root user it’s finding a different version of numpy. You could install the same version of numpy site-wide (i.e. as root), or you could try editing jetson-inference/utils/python/bindings/FindNumPy.cmake:19 like so:

execute_process(COMMAND "sudo" "-u" "MY_USER" "${PYTHON_EXECUTABLE}" "-c"

(replace MY_USER with your actual username - this is temporarily hacky but if it works you could set it in cmake another way, like as the output of whoami)

I was doing some researching digging into this, but was unable to find a way to robustly detect the virtualenv dist-package/site-package module install dir via cmake. So unfortunately it may be easiest to manually work around it for now, sorry about that.

I cleaned the build folder, added a -DCMAKE_INSTALL_PREFIX path, and then still had to modify some of the cmake_install files here and there, but I think I finally got it working. It wasn’t pretty, but I"ll do some testing now to see if I built it right.

Thanks
Marc

It seems to have worked and I can now import jetson.utils and jetson.inference, but not jetson_inference. When I try I get:

ModuleNotFoundError: No module named ‘jetson_inference’

Any ideas what’s missing? Did I miss a config option somewhere? I’ll double check my changes to the install files

Can you confirm that jetson-inference/python/python/jetson_inference got installed? That resolves the module name and loads the extension library. I would try adding some debug print() statements to that __init__.py

It was not installed, but I manually copied it over and it works now. However when I run a program that reads frames from a video file I see the log flooded with messages like:

nvbuf_utils: dmabuf_fd 1081 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1085 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1083 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1087 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1089 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1063 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1067 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1069 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…
nvbuf_utils: dmabuf_fd 1065 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed… Exiting…

I rebuilt with -DENABLE_NVMM=off, but that doesn’t seem to have made a difference. Any ideas?

Actually, that made things worse. I think I broke something because my code now says:

Traceback (most recent call last):
File “./runengine.py”, line 3, in
from uatuEngine import UatuEngine
File “/home/marc/src/george_python3.7/device_jetson/src/uatuEngine.py”, line 13, in
from jetson_inference import poseNet
File “/home/marc/venvirons/p37test/venv/lib/python3.7/site-packages/jetson_inference/init.py”, line 8, in
from jetson_inference_python import *
ImportError: dynamic module does not define module export function (PyInit_jetson_inference_python)

I get the same error when I try to run poseNet.py. I’ll re-rebuild without the ENABLE_NVMM=off flag and make sure that at least gets me back to functioning.

Yes, rebuilding without that flag returns things to working properly. Interestingly enough the poseNet.py demo doesn’t have this issue, so perhaps it’s reading it’s input in a different way. I’ll have to compare it to my code to see what’s different.

Unfortunately those nvbuf_utils log messages can’t be disabled, unless like you found, you entirely disable using NVMM. However I’m not sure how disabling NVMM would give you that ImportError. I’m guessing you re-ran make && sudo make install after, but may you had other steps.

Despite the log messages, does it still load/process the video ok?

Yes, it still seems to run ok. I did another build tonight and I’m not sure what I missed last time but this time it seems to build/run ok. I think that gets me up and running. I appreciate all your patience and help!

Thanks again very much!

OK gotcha, no problem @mjasner - glad you got it working!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.