Import error in conda env when use ncu to profile python file

Hi, I’m in a conda env, and I’m trying to profile a python file using ncu with sudo ncu --metrics launch__cluster_size python -u, when I profile without sudo, it worked well, but an error ImportError: cannot open shared object file: No such file or directory occured with sudo.
Could anyone help to solve this problem?

sudo mostly likely changes the python version you are using and thus dependency installed in the particular conda env you’re using won’t be visible.
You should be able to verify this by running sudo which python versus which python. The former probably yields something like /usr/bin/python while the latter should give you something like /<anaconda_path>/envs/<env_name>/bin/python. Specifying the full path to the python version you want to use should solve the issue.

Hi, I tried to use python in miniconda, but the error still exists.

The error is from not ncu. Please make sure the script can run successfully separately before using the tools.

Hi, I can run do successfully without root, but as mentioned above, sudo mostly likely changes the python version I’m using, and I need to use the python version and other packages in conda environments, I need to use sudo to make sure ncu works as well as possible. What can I do to solve the problem? Or I just need to make sure that can be executed well in sudo?

You should firstly make sure can be executed well in sudo.
And then we can see if any error reported for NCU.

Thanks for your help, I will try it later~

If your application is sensitive to having its environment setup properly, you can also invoke sudo with -E to forward your user’s environment into the elevated shell.

1 Like

Thanks a lot!!! It really works~