Author Topic: Installation to get python script to work in gui  (Read 147 times)

MS

  • Newbie
  • *
  • Posts: 5
Installation to get python script to work in gui
« on: April 05, 2018, 01:58:32 PM »
Hi, I am trying to get to grips with ovito in the gui. I can load in a dataset etc and as far as I can tell everything else is working but I am now trying to explore the python scripting interface. In the script output it just says: "Failed to initialize Python interpreter." and no python scripts will run. Initially I Downloaded 2.9.0 from the site. I read about python version being important so then tried 3.0.0 which I believe supports python 3.5. Both give the same error.

I'm using:
Ubuntu 16.04 LTS,
python 3.5.2

I am using a virtual environment could this be the issue? Could this be responsible? How do I make sure Ovito can "find" my python distribution?

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 409
Re: Installation to get python script to work in gui
« Reply #1 on: April 05, 2018, 02:14:04 PM »
Hi,

Ovito ships with its own Python 3.x interpreter and under normal circumstances it should work out of the box. However, the isolation from the system environment may not be perfect. In your case, there seems to be something unusual on your system that interferes with Ovito's Python interpreter. My current hypothesis is that there are some environment variables being picked up by the Ovito interpreter, making it access config files or packages from another Python interpreter on your system, which is incompatible. I would like to find out what it is.

Have you already tried running the "bin/ovitos" interpreter executable from the terminal? Perhaps if shows some additional log output on why the initialization fails. Then check the environment variables set on your system. Perhaps there are some Python related variables that you can clear first before executing Ovito or "ovitos". If possible, please post the output of the "printenv" terminal command here.

-Alex

MS

  • Newbie
  • *
  • Posts: 5
Re: Installation to get python script to work in gui
« Reply #2 on: April 05, 2018, 02:53:38 PM »
thanks for your swift reply

-typing bin/ovito at the command prompt inside my virtual environment produces no output
-when I then try to add python overlay in the gui I get the following:

Traceback (most recent call last):
  File "/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/__init__.py", line 25, in <module>
    import ovito.vis
  File "/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/vis/__init__.py", line 36, in <module>
    import PyQt5.QtGui
ImportError: /home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/libQt5Core.so.5: version `Qt_5.9' not found (required by /home/ppzmis/.local/lib/python3.5/site-packages/PyQt5/QtGui.so)
Traceback (most recent call last):
  File "/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/__init__.py", line 25, in <module>
    import ovito.vis
  File "/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/vis/__init__.py", line 36, in <module>
    import PyQt5.QtGui
ImportError: /home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/libQt5Core.so.5: version `Qt_5.9' not found (required by /home/ppzmis/.local/lib/python3.5/site-packages/PyQt5/QtGui.so)


printenv gives the following output:

XDG_VTNR=7
XDG_SESSION_ID=c1
VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
CLUTTER_IM_MODULE=xim
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/ppzmis
GPG_AGENT_INFO=/home/ppzmis/.gnupg/S.gpg-agent:0:1
SHELL=/bin/bash
TERM=xterm-256color
VTE_VERSION=4205
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
WINDOWID=56726409
OLDPWD=/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1065
GNOME_KEYRING_CONTROL=
GTK_MODULES=gail:atk-bridge:unity-gtk-module
USER=ppzmis
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
QT_ACCESSIBILITY=1
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
VIRTUAL_ENV=/home/ppzmis/.virtualenvs/Sims
WORKON_HOME=/home/ppzmis/.virtualenvs
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
PATH=/home/ppzmis/.virtualenvs/Sims/bin:/home/ppzmis/bin:/home/ppzmis/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
DESKTOP_SESSION=ubuntu
VIRTUALENVWRAPPER_HOOK_DIR=/home/ppzmis/.virtualenvs
QT_IM_MODULE=ibus
QT_QPA_PLATFORMTHEME=appmenu-qt5
XDG_SESSION_TYPE=x11
PWD=/home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64
JOB=gnome-session
XMODIFIERS=@im=ibus
GNOME_KEYRING_PID=
LANG=en_GB.UTF-8
GDM_LANG=en_GB
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
IM_CONFIG_PHASE=1
COMPIZ_CONFIG_PROFILE=ubuntu
PS1=(Sims) \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
GDMSESSION=ubuntu
SESSIONTYPE=gnome-session
GTK2_MODULES=overlay-scrollbar
HOME=/home/ppzmis
XDG_SEAT=seat0
SHLVL=1
LANGUAGE=en_GB:en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
UPSTART_INSTANCE=
UPSTART_EVENTS=started starting
XDG_SESSION_DESKTOP=ubuntu
LOGNAME=ppzmis
QT4_IM_MODULE=xim
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/var/lib/snapd/desktop
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-opvuHm6i8K
LESSOPEN=| /usr/bin/lesspipe %s
VIRTUALENVWRAPPER_WORKON_CD=1
INSTANCE=Unity
UPSTART_JOB=unity-settings-daemon
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
GTK_IM_MODULE=ibus
LESSCLOSE=/usr/bin/lesspipe %s %s
XAUTHORITY=/home/ppzmis/.Xauthority
_=/usr/bin/printenv

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 409
Re: Installation to get python script to work in gui
« Reply #3 on: April 05, 2018, 03:12:22 PM »
Note that I asked you to run "bin/ovitos", not "bin/ovito" in the terminal. "ovito" is the graphical program version, "ovitos" is the interactive script interpreter, similar to "python". Please try to deactivate your virtual environment.  The following line from the error message indicates that the PyQt5 Python module was somehow imported from a directory outside of the Ovito installation:

ImportError: /home/ppzmis/Documents/SimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/libQt5Core.so.5: version `Qt_5.9' not found (required by /home/ppzmis/.local/lib/python3.5/site-packages/PyQt5/QtGui.so)

Instead, this module should have been imported from the internal package directory:

/ovito-3.0.0-dev155-x86_64/lib/python3.5/site-packages/PyQt5/

I am not really familiar with how virtual environments work, but something in the environment must be convincing Ovito's interpreter to load modules from /home/ppzmis/.local/lib/python3.5/ instead of the internal package directory.

MS

  • Newbie
  • *
  • Posts: 5
Re: Installation to get python script to work in gui
« Reply #4 on: April 05, 2018, 03:17:08 PM »
ok I have deactivated my virtual environment and having cd to the ovito-3.0.0-dev155-x86_64 directory I ran "bin/ovitos". Output is as follows:

Traceback (most recent call last):
  File "/home/ppzmis/Documents/Data/ParticelSimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/__init__.py", line 25, in <module>
    import ovito.vis
  File "/home/ppzmis/Documents/Data/ParticelSimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/plugins/python/ovito/vis/__init__.py", line 36, in <module>
    import PyQt5.QtGui
ImportError: /home/ppzmis/Documents/Data/ParticelSimData/ovito-3.0.0-dev155-x86_64/bin/../lib/ovito/libQt5Core.so.5: version `Qt_5.9' not found (required by /home/ppzmis/.local/lib/python3.5/site-packages/PyQt5/QtGui.so)
ERROR: Failed to initialize Python interpreter.



Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 409
Re: Installation to get python script to work in gui
« Reply #5 on: April 05, 2018, 03:31:49 PM »
Ok, thanks. This shows that the problem is not related to the virtualenv. Rather the $HOME/.local/lib/python3.5/site-packages is among the default locations where Python interpreters search for modules and, unfortunately, it has a higher priority than Ovito's internal site package directory. Thus, Python modules like the PyQt5 module that are also present in your user directory shadow Ovito's internal modules.

For testing purposes, you can temporarily rename the /home/ppzmis/.local/lib/python3.5/site-packages/PyQt5/ directory to see if that solves the problem.

I am still trying to figure out a way to convince Ovito not to look in the user package directory at all.

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 409
Re: Installation to get python script to work in gui
« Reply #6 on: April 05, 2018, 03:43:24 PM »
Here is a way to do it: Open the file ovito-3.0.0-dev155-x86_64/lib/python3.5/site.py in a text editor and change line 80 from

ENABLE_USER_SITE = None

to

ENABLE_USER_SITE = False

After this change, Ovito's Python interpreter should ignore your user package directory.

MS

  • Newbie
  • *
  • Posts: 5
Re: Installation to get python script to work in gui
« Reply #7 on: April 05, 2018, 03:49:49 PM »
That works. Thank you very much for debugging that I'd never of figured it out.