I'm running this Python script on my (Debian) server to write out an animation from vtk data:
import paraview.simple as pv
pv.servermanager.LoadState('plot.pvsm')
pv.SetActiveView(pv.GetRenderView())
pv.WriteAnimation('images/bj.png', Quality=2)
It is supposed to create this animation while I'm not logged on the server. For that I use screen and run the script with:
pvbatch --use-offscreen-rendering plot3d.py &
It does its job well by writing the image files. However, when I detach from the screen session and log out the script stops completely.
In my understanding the option --use-offscreen-rendering should make sure that no rendering on my screen happens. This works on my client machine where I can run the same script and kill the terminal and the script continues.
Maybe relevant: For every image I get the error message:
libGL error: failed to authenticate magic 1
libGL error: failed to load driver: i965
where the number after "magic" increases with each image.
My system:
Debian Linux 3.16.7-ckt11-1 (2015-05-24), kernel 3.16.0-4-amd64
Paraview 4.1.0
Python 2.7.9
Screen 4.02.01
You still need access to X server even though you're using --use-offscreen-screen flag. If you want truly offscreen, you should rebuild your ParaView with OSMesa support as described here
Related
Here's the breakdown of my Windows WSL environment:
Windows 11
WSL version 2
Ubuntu version 20.04.3 LTS
Python 3.8.10
I have a super simple Python program I'm using to open a web page in my default browser.
Here is my code:
import webbrowser
webbrowser.open('https://github.com')
When I run this from my terminal the webpage opens up as expected, but I also get this error in the terminal:
tcgetpgrp failed: Not a tty
When my terminal displays this message, the cursor goes down to the next line and it looks like a process is hung or something. To be able to use the terminal I have to Ctrl+C to get it to give me the command prompt.
I looked for answers and everything I could find has to do with using Jupyter or PHP but I'm not using either of them, I'm just using plain old Python to try and open the browser.
Can anyone tell me what the issue is here and how to fix this/prevent it from happening?
Yes, I can also reproduce it from the Python (and IPython) REPL on Ubuntu under WSL. I don't get the "lockup" that requires Ctrl+C when running interactively, at least.
I'll theorize on the "why". Most of this I can confirm myself, but the last bullet below is still a bit of a mystery to me:
webbrowser-open uses whatever browser is defined by the BROWSER environment variable first, but falls back to (I believe) xdg-open.
xdg-open uses whatever browser is defined in the alternatives system for x-www-browser or www-browser.
On Ubuntu 20.04 on WSL, the wslu package is installed by default (it is no longer a default package under 22.04, though).
That package includes the wslview helper. From its manpage:
[wslview] is a file viewer on WSL that allows you to open files and folders from WSL in Windows and a fake web browser that allows opening urls in your default browser on Windows 10.
wslview is registered during the wslu installation as the alternative for both x-www-browser and www-browser.
webbrowser.open doesn't just call xdg-open, but it attempts to get the process information of the resulting browser so that it can (at the least) raise the window if requested. Part of this is obtaining the process group via, apparently, the tcgetpgrp system call. According to the tcgetpgrp manpage:
The function tcgetpgrp() returns the process group ID of the foreground process group on the terminal associated to fd, which must be the controlling terminal of the calling process.
Here's where I have to "hand-wave" a bit -- Something in the hand-off from webbrowser.open to wslview to binfmt_misc (the kernel system that allows it to launch Windows executables) is "losing" or redirecting a file descriptor of the terminal, resulting in this message.
It appears to me to be a bug (unintended side-effect?) of wslview, since making sure it isn't used will prevent the error from occurring.
As a workaround, either:
export BROWSER=/mnt/c/path/to/windows/browser before starting Python. Note that I'm not sure how to point to Edge, since it's there's no ".exe" for it that I'm aware of (it's a Universal/Modern/UWP/whatever app).
Or, since you are on Windows 11, install a Linux browser. I used Vivaldi to test and confirm that it opened properly from Python under WSL. Note that you can't sudo apt install either Chromium or Firefox under WSL since they are both Snaps.
I am trying to program my lego mindstorms inventor robot using python and this pypi package. It basically uses rshell to communicate with the lego robot that is running micropython. Here is the code that I am trying to execute.
from mindstorms import Hub
hub = Hub()
motor = hub.port.E.motor
print(motor)
motor.run_for_degrees(270)
When I run this code line by line in the python shell in the terminal everything works as expected. The motor turns. However, if I put this in a .py file, I get this error. rshell.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 1, in <module>\r\nAttributeError: \'NoneType\' object has no attribute \'run_for_degrees\'\r\n'
Seems like the issue is that the motor is not being detected by the brain when I run the script in a .py file.
I made another script for diagnostics. It is sending messages directly to the robot without using the pypi package.
board = Pyboard(device)
board.enter_raw_repl()
print(board.exec_("import hub;print(hub.port.A.info())"))
The result is "None". The brain by itself is detected because commands such as print(board.exec_("import hub;print(hub.info())")) run successfully. When I am trying to get any information about the port, the result is None, which makes me believe that the connected motor is not detected by the .py file. Again, if I simply run all this code in the python shell it works perfectly. I am confused by this irregular behavior.
Here are the steps that I took to troubleshot this(none of them worked):
Tried to run a .py file from the terminal using exec() function, and still get the error that the motor is None.
Checked that the python version of the shell and the version of the python that is running the .py file is the same.
Running this script on different machines.
Reinstalled lego mindstorms firmware and ensured that the latest version is running.
Any suggestions why this would this problem occur?
The issue is that you need to wait a few seconds after the initialization of the Mindstorms brain before performing any kind of motor initialization.
from mindstorms import Hub;
import time
hub = Hub();
time.sleep(2)
print(hub.port.A.motor);
hub.port.A.motor.run_for_degrees(30);
So I'm playing with python3 on Cloud9, got interested in trying pygame and found a recommendation to install cloud9-vnc for a desktop display. Got both of those things to work, but not in tandem. I'm a rather newbish with Linux and VNC, so I'm stuck at the moment. Any chance I can get pygame output on a VNC desktop?
What I have so far is that I've installed pygame using this and cloud9-vnc using this. Pygame import and commands run smoothly (both in terminal and script) and when I run the script with c9vnc I get the link to a VNC desktop. However, the desktop is clear, apart from Ubuntu logo.
The program doesn't actually seems to be running, considering that it doesn't display the text to be printed
In fact, it seems that it's not even started to run.
However, inside the VNC desktop I have the access to complete cloud9 workspace, including installed pygame, which does work, albeit a bit more clunky, compared to cloud9's interface.
So what I want to ask is is there a way for me to write and run a code on cloud9's default interface that would directly display the output in VNC's desktop, with little to no additional interaction?
I set up PyCharm for remote debugging according to this tutorial on CodeProject
http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm
I am now wondering if it is possible to execute a Python Script with the help of PyCharm on the RaspberryPI and receive the output in PyCharm. Specifically I want to do some image processing and display the image with the help of OpenCV. It would be great to get the image displayed on my Windows machine, not on the Pi.
Another usecase, I want to create some matplot figure, execute the script on the pi and show the Output back in PyCharm on my Windows machine.
Is this possiple?
Kind Regards
You can do this using OpenCV Image Viewer Plugin. Debug you program using remote interpreter in Pycharm, stop at the breakpoint and choose "View as image".
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin
I'm using pygame on a PC (PC-104) with ubuntu server, for this reason it only has terminal, not UI.
On my laptop the code works perfecly, running the code on the terminal "eg: python game.py", but on the PC104 it gives "Video system not initialized", I read the error is shown because it is a way to use events on a system without UI?
Thanks.
Thank for your answer jsbueno. I was able to found a solution a few weeks ago but forget to answer the question.
I wasn't able to run any pygame script with any other library than X11. But I found that one can run the script with no graphics library. Just setting the SDL_VIDEOLIBRARY enviroment variable to "dummy".
This is posible on bash but I prefer to do it on python:
os.environ["SDL_VIDEODRIVER"] = "dummy"
With this I was able to run the pygame script, detect joystick events, etc.
It is possible to run pygame programs in a system without X11 if you set it to use framebuffer or vgalib - the docs even talk about using aalib (which would display graphics using ascii art on the terminal.)
This part of the documentation has it:
Pygame will select from one of several internal display backends when
it is initialized. The display mode will be chosen depending on the
platform and permissions of current user. Before the display module is
initialized the environment variable SDL_VIDEODRIVER can be set to
control which backend is used. The systems with multiple choices are
listed here.
Windows : windib, directx
Unix : x11, dga, fbcon, directfb,
ggi, vgl, svgalib, aalib
So, what you have to do is set the SDL_VIDEODRIVER environment variable before starting your code. And being shure the proper lib. is installed.
For more information:
http://www.pygame.org/docs/ref/display.html