I have a library that I use from python . Interaction according to this scheme .

The problem is this: the python process works with superuser rights, but the library functions from the library that are called by this process work without superuser rights, and therefore return an error.

How to be in this situation?

Update: I work with django . Initially I tried to run compiled object files from python - it works as it should.

But in views.py tried to call it using different methods (for example, such ) - it didn't work out:

[Errno 2] No such file or directory

although the object file is in the same directory as views.py .

  • How do you determine that "the python process works with superuser rights" and "functions ... work without superuser rights"? Please add this information to the question. at the same time, it would not hurt to specify the operating system used. - aleksandr barakin
  • I work in Raspbian on Raspberry PI. File run sudo python file.py I determined it simply - I ran the Python code, which calls the sishny both with the superuser's rights, and without it, and received many times the same error result. - Vladislav
  • What does "Sishny code" mean in your question? 1. foo.so file, with foo foo.so for Python, which is simply imported: import foo 2. libfoo.so Sishnaya library that you want to use with ctypes, cffi 3. ./foo executable file that you can run using subprocess module. - jfs

1 answer 1

accordingly return an error:

[Errno 2] No such file or directory, despite the fact that the object file is in the same directory as views.py

the error is not related to the absence / presence of any rights. in general, “child” processes (by default) inherit privileges from the process that spawned them.

The error is caused by the fact that you do not have ms / windows , but gnu / linux , and the search for libraries (by default) is not performed in the current or in any other arbitrary directory.

can try to add current directory . (or any other necessary one) - to the LD_LIBRARY_PATH environment LD_LIBRARY_PATH , for example, like this:

 $ LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH python file.py 

if sudo used, then most likely a command of the form:

 $ LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH sudo python file.py 

will have no effect - surely sudo in your system is configured to ignore LD_LIBRARY_PATH from environment variables, therefore this variable should be passed to the sudo program explicitly when called as a parameter:

 $ sudo LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH python file.py