libonvif icon indicating copy to clipboard operation
libonvif copied to clipboard

AttributeError: module 'libonvif' has no attribute 'Session'

Open akash1551 opened this issue 1 year ago • 9 comments

(myenv) ➜ onvif onvif-gui Traceback (most recent call last): File "/home/awankhede/src/onvif/myenv/bin/onvif-gui", line 5, in <module> from gui.main import run File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/__init__.py", line 1, in <module> from .main import MainWindow File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/main.py", line 44, in <module> from gui.panels import CameraPanel, FilePanel, SettingsPanel, VideoPanel, AudioPanel File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/panels/__init__.py", line 1, in <module> from .camerapanel import CameraPanel File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/panels/camerapanel.py", line 26, in <module> from gui.onvif import NetworkTab, ImageTab, VideoTab, PTZTab, SystemTab, LoginDialog, \ File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/onvif/__init__.py", line 7, in <module> from .datastructures import Session, StreamState, MediaSource, Camera File "/home/awankhede/src/onvif/myenv/lib/python3.10/site-packages/gui/onvif/datastructures.py", line 41, in <module> class Session(onvif.Session): AttributeError: module 'libonvif' has no attribute 'Session'

I am getting this error after installing onvif-gui on 'onvif-gui' command.

I followed following commands for installation. virtualenv -p /usr/bin/python3.10 myenv pip3.10 install onvif-gui

akash1551 avatar Aug 22 '24 10:08 akash1551

Hello,

Thank you for reaching out. The error you are experiencing is a result of a compilation failure of the python modules. There are a few possibilities as to why this might occur.

It's possible that the pip install did not occur within the intended virtual environment. This would happen if the environment was not activated during installation, but was activated when trying to run the application. The commands shown at the end of the post might result in this condition, as they don't show the environment being activated prior to the pip install.

Another possibility is that dependencies are missing. On Ubuntu, the dependencies are installed using the command

sudo apt install cmake g++ git python3-pip virtualenv libxml2-dev libavdevice-dev libsdl2-dev '^libxcb.*-dev' libxkbcommon-x11-dev

If neither of these turns out to be the issue, it is possible to get more detailed information by using the Build From Source instructions. The output of the assets/scripts/compile command will produce a detailed log of the compilation process that can provide better information on the results of the installation that can be used for troubleshooting.

Hopefully these instructions are helpful, please let me know if you would like further assistance.

Best Regards,

Stephen

sr99622 avatar Aug 22 '24 13:08 sr99622

@sr99622 Thank you for your response. My machine has python3.10 alongwith python3.8, maybe it was buiding using 3.8, so I am running it using docker now. Its running fine within docker. posting here Dockerfile and associated commands.

'''

Use an official Ubuntu base image

FROM ubuntu:22.04

Set environment variables

ENV DEBIAN_FRONTEND=noninteractive

Install required dependencies

RUN apt-get update && apt-get install -y
software-properties-common
wget
curl
build-essential
libssl-dev
zlib1g-dev
libbz2-dev
libreadline-dev
libsqlite3-dev
libffi-dev
libncurses5-dev
libgdbm-dev
libnss3-dev
liblzma-dev
tk-dev
libxml2-dev
libxmlsec1-dev
liblz4-tool
xz-utils
git RUN apt-get clean RUN apt-get install -y cmake g++ git python3-pip virtualenv libxml2-dev libavdevice-dev libsdl2-dev '^libxcb.*-dev' libxkbcommon-x11-dev RUN apt-get install -y qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools RUN apt-get install -y libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0 x11-xserver-utils

Install Python 3.10

RUN add-apt-repository ppa:deadsnakes/ppa -y RUN apt-get update RUN apt-get install -y python3.10 python3.10-venv python3.10-dev python3-pip RUN apt-get clean RUN mkdir -p /root/Videos

Create and activate a virtual environment

RUN python3.10 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH"

Upgrade pip and install onvif-gui

RUN pip install --upgrade pip RUN pip install onvif-gui

Expose the necessary port

EXPOSE 5000

Command to run the application

CMD ["onvif-gui"]

'''

` docker build -t onvif-gui:latest .

xhost +local:docker

docker run -it --network host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -e LIBGL_ALWAYS_SOFTWARE=1 --entrypoint="/bin/bash" onvif-gui:latest -c "mkdir -p /root/Videos && onvif-gui" `

akash1551 avatar Aug 30 '24 06:08 akash1551

same issue on debian/sid

I have installed all the deps as suggested but I still get the same error message

I also don't understand the reason of all these -dev, since I could do pip install onvif-gui succeessfully without most of such -dev packages. Bloating the OS with unnecessary packages is not a good idea.

Imo, providing an appimage of onvif-gui would be a much practical way to distribute it

cipitaua avatar Dec 23 '24 10:12 cipitaua

Thank you for reaching out, it is unfortunate that the installation is not going well for your configuration. Most of the steps listed above on this page are not really necessary for a standard install on Onvif GUI, I think that configuration was specialized with multiple python versions and a Docker container. Normally only a few dev packages are required, which are listed in the install instructions. I agree that bloating the OS is not a good idea.

The installation procedure in general deserves another look, it is more complex than I would prefer.

Having said that, I would like to help get you up and running on Debian sid. This is a platform that should install without issues, so the error is a little concerning. The message AttributeError: module 'libonvif' has no attribute 'Session' indicates that the libonvif python module did not compile properly. The dependency in this case is libxml2-dev which is generally a pretty stable package.

I will fire up a Debian sid machine and see if I can replicate. If you are so inclined, running the command assets/scripts/compile from the libonvif root folder will generate a detailed log of the compilation process, which could provide some more data to help trouble shoot the problem.

Best Regards,

Stephen

sr99622 avatar Dec 24 '24 19:12 sr99622

Hello, I realized there's the package 'onvif-tools' in the official debian repos. Luckily there's no need to compile.

cipitaua avatar Dec 26 '24 08:12 cipitaua

Same issue on linux mint 21, tried both pip install and git build method

cptnmidnight avatar Jan 30 '25 07:01 cptnmidnight

Thank you so much for reaching out, the feedback is greatly appreciated. This is an issue that has come up in several variations throughout the life of the project. The installation process presents a number of challenges, and the error you have experienced is the result of it's failure. Most often, the failure is caused by the presence of multiple versions of python or other libraries on the installation target machine.

On Linux, the application is designed to compile from source using algorithms that detect the locations of python, ffmpeg and libxml2 libraries. Testing for installation is done on clean installs, so variations in machines that experience configuration evolution is not accounted for, unfortunately. The error messages from the git build method may provide clues to remedy the install if you are familiar with compiling programs, its usually a matter of getting the environment variables pointing to the right python version.

I have been putting some thought into this process, and have received some suggestions on how to resolve the issue. One approach is to use Docker install, which requires some testing but may be a viable solution.

Another approach to use would be to use pre-compiled python modules and avoid the compilation process entirely. This has some interesting benefits but may be susceptible to version issues in the underlying libraries, which are quite complex, so further testing would be required for this approach as well.

In the end, some combination of the two may be the result. In any event, I will post here to announce the release.

Thank you once again for your interest in the project.

sr99622 avatar Jan 30 '25 16:01 sr99622

I had the same problems on Ubuntu 20.04 when building the library. The problems I faced were:

  • Ubuntu 20.04 comes with Python 3.8, so I had to install python 3.10 using deadsnakes ppa. (Do NOT override the default python3 in Ubuntu. Always run with Python3.10 ...)
  • The Cmake Requirements in most CMakeLists.txt were 3.17, while Ubuntu 20.04 comes with Cmake 3.16.
  • libavio's CMakeLists.txt has incorrect linking of SDL2 library. Replacing "SDL2::SDL2" with "SDL2" and adding (under pybind11_add_module...)
target_include_directories(avio PUBLIC
        include
        ${FFMPEG_INCLUDE_DIRS}
        ${SDL2_INCLUDE_DIRS}
    )

Solved the issue. I was able to build and run the program.

krzmancd avatar Mar 13 '25 09:03 krzmancd

Thank you so much for posting this information, it is very useful. As you can see, the installation process is difficult for the application. I have been exploring many different techniques for simplification and I believe I am getting close to a workable solution, but progress has been very slow and difficult. Being able to compile on Ubuntu 20.04 may actually be a significant milestone in the process.

If I may digress, building a binary installation on linux is extremely difficult and is a known shortcoming of the platform. The main stumbling block is the compatibility with glibc, which evolves with the kernel. Supposedly, the kernel is maintained such that backward compatibility is preserved, which I have observed to be true at least from 22.04 -> 24.04 and up. A technique commonly used is to compile binaries on the oldest platform possible, which will enable the installation on later versions of the kernel and associated glibc, so being able to compile on 20.04 will open up a large number of installations if compatibility holds. The ultimate goal is a fully installable binary which includes the python libraries integrated, but the first intermediate step will be a python pip package that is binary, rather than compiled.

Just as note, I found the docker installation to have a bunch of issues that made it not really any better than the compiled python installation. This has to do with the hardware interface with GPU (especially NVIDIA) and sound devices as well as the existence of a large number of unofficial Docker executables found in the wild that do not have proper interfaces for the application. Fixing these issues required complex workarounds or the removal and re-installation of Docker versions which I felt made it an unattractive option.

Unfortunately, this is a very slow and tedious process which requires extensive testing. I have made significant progress in this direction and hope to have a new release available soon. Additionally, I have a number of bug fixes ready that should correct the remaining run time issues with the application, those regarding file operations and some audio issues. These fixes I have held back as full testing is required for everything and is a time consuming process, so I'm trying to test all features in one comprehensive pass. Your work with the compilation will save me a lot of effort in the process, and I am grateful for this feedback. I hope you find the application useful.

Many Thanks,

Stephen

sr99622 avatar Mar 13 '25 16:03 sr99622