In Linux on my Chromebook, I am trying to take a screenshot using the command line, but nothing seems to be working. I have tried ImageMagick...
sudo apt-get install imagemagick
import -window root filename.png
# "unable to read X window image 'root'"
import filename.png
# "unable to grab mouse '': No such file or directory"
And I have also tried scrot...
sudo apt-get install scrot
scrot -u filename.png
#"BadDrawable (invalid Pixmap or Window parameter)"
I tried several python methods, but the only one that I could successfully install and get to run without errors was pyscreeze (which uses scrot), and it produced nothing but a blank, black image, which is useless to me.
In terms of other python methods, I tried pyautogui which failed to install, telling me "Failed building wheel for Pillow." I tried pyscreenshot, which installed and ran but told me "All backends failed." I also tried ImageGrab, which told me "ImageGrab is MacOS and Windows only."
Does anyone know of a way to make this work?
Thanks in advance!
Javascript solution
Here is a way to take a screenshot of any part of the chromebook's screen, a chrome window, or a chrome tab.
Paste this into your browser console to take a screenshot.
async function takeScreenshot(format = "image/png") {
const stream = await navigator.mediaDevices.getDisplayMedia({video:true});
const video = document.createElement("video");
video.srcObject = stream;
video.muted = true;
await video.play();
const canvas = document.createElement("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
const context = canvas.getContext("2d");
context.drawImage(video, 0, 0);
const blob = await new Promise(resolve => canvas.toBlob(resolve, format));
stream.getTracks().forEach(track => track.stop());
return blob;
}
function download(blob, name = "Untitled") {
const elt = document.createElement("a");
elt.download = name;
elt.href = URL.createObjectURL(blob);
elt.click();
URL.revokeObjectURL(elt.href);
}
takeScreenshot("image/png").then(blob => download(blob, "Screenshot.png"));
I don't have a solution but an idea how to do this
You need chromebook in developer mode to have access to the actual Linux console, not the virtual machine linux that you install via "settings" app
As chromebook is on Wayland, you need to use something like grim which works on Wayland and not scrot which is for X Windows
You could use native wayland-enabled Linux chroot like https://github.com/nmilosev/crouton-fedora-wayland to install grim and other wayland native tools
Related
Similar question have been asked here an year ago but no answer yet.
Im running a Python script via Java and I'm getting
ImportError: No module named numpy in <script> at line number 1
This is my code:
public void runScript(String filePath) throws Exception {
StringWriter writer = new StringWriter();
ScriptContext context = new SimpleScriptContext();
context.setWriter(writer);
Options.importSite = false;
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("python");
engine.eval(new FileReader(filePath), context);
System.out.println(writer);
}
How do I run script with it's imports?
Of course all the required installations have been installed (with pip install) and that the code runs perfectly when I run it not through java.
I was trying to run through some of the examples from pyinfra's docs to see if this tool would work for me (so I could manage some servers using good old Python) and I even found they had an example for installing virtualbox on a host machine, but I can't get even the example working. I'm getting a weird error that makes me think there's been an update to the tool since the examples, and even the docs, have been updated. Just wondering if anyone else has a way to get this to work with pyinfra (currently trying with version 1.5).
The example code:
from pyinfra import config, host
from pyinfra.facts.server import LinuxDistribution, LinuxName, OsVersion
from pyinfra.operations import apt, python, server
config.SUDO = True
virtualbox_version = '6.1'
def verify_virtualbox_version(state, host, version):
command = '/usr/bin/virtualbox --help'
status, stdout, stderr = host.run_shell_command(state, command=command, sudo=config.SUDO)
assert status is True # ensure the command executed OK
if version not in str(stdout):
raise Exception('`{}` did not work as expected.stdout:{} stderr:{}'.format(
command, stdout, stderr))
if host.get_fact(LinuxName) == 'Ubuntu':
code_name = host.get_fact(LinuxDistribution)['release_meta'].get('DISTRIB_CODENAME')
apt.packages(
name='Install packages',
packages=['wget'],
update=True,
)
apt.key(
name='Install VirtualBox key',
src='https://www.virtualbox.org/download/oracle_vbox_2016.asc',
)
apt.repo(
name='Install VirtualBox repo',
src='deb https://download.virtualbox.org/virtualbox/debian {} contrib'.format(code_name),
)
# install kernel headers
# Note: host.get_fact(OsVersion) is the same as `uname -r` (ex: '4.15.0-72-generic')
apt.packages(
{
'Install VirtualBox version {} and '
'kernel headers for {}'.format(virtualbox_version, host.get_fact(OsVersion)),
},
[
'virtualbox-{}'.format(virtualbox_version),
'linux-headers-{}'.format(host.get_fact(OsVersion)),
],
update=True,
)
server.shell(
name='Run vboxconfig which will stop/start VirtualBox services and build kernel modules',
commands='/sbin/vboxconfig',
)
python.call(
name='Verify VirtualBox version',
function=verify_virtualbox_version,
version=virtualbox_version,
)
Here is the error that I'm seeing:
File "install_virtualbox.py", line 21, in <module>
if host.get_fact(LinuxName) == 'Ubuntu':
AttributeError: module 'pyinfra.api.host' has no attribute 'get_fact'
I checked the source and I can't argue with my editor when it says it 'cannot find a reference to config' or 'init', as I don't see them either. But then how is anyone getting facts about hosts? Looks like the logic may have been moved to the 'pyinfra.api.host' and 'pyinfra.api.config' packages, but the logic there looks totally different.
Hoping I'm just missing something that someone who's been using the tool can help explain to me.
I have created the SConstruct to install the systemd user services but when I try to scons uninstall the temporary services files are creates which should not happen.
import os
PATH_WD = os.path.abspath(os.curdir)
env = Environment(
SUBSTFILESUFFIX = '.service',
SUBST_DICT = { '{{PATH_ROOT}}' : os.path.dirname(PATH_WD) },
ENV = {
'DBUS_SESSION_BUS_ADDRESS' : os.environ['DBUS_SESSION_BUS_ADDRESS'],
'XDG_RUNTIME_DIR' : os.environ['XDG_RUNTIME_DIR']
}
)
INSTALLED = env.Install(
target = os.path.expanduser('~/.config/systemd/user/'),
source = [
env.Substfile('service1'),
env.Substfile('service2'),
]
)
env.AddPostAction(INSTALLED, env.Action('systemctl --user daemon-reload'))
Alias('install', INSTALLED)
NoClean(INSTALLED)
Command('uninstall', INSTALLED, Delete(INSTALLED))
Default('install')
Second try..
Here's a trivial example which should work for you..
env=Environment()
prog=env.Program('main.c')
Default(prog)
installed_prog = env.Install('install_dir', prog)
Alias('install', installed_prog)
NoClean(installed_prog)
# You don't have to specify targets to Alias.. so it won't
# try to build those before executing the Action
Alias('uninstall', action=Delete(installed_prog))
AlwaysBuild('uninstall')
SCons builder calls are statements of relationships between nodes. You've associated the target "uninstall" with the source INSTALLED by calling the Command builder. So in order to "build" this target, you need the source, and the source is the list of nodes returned by calling the Install builder. So the Install has to happen before the uninstall can take place. Is there a reason you don't want SCons' clean functionality to be used here? To see this, try: scons --tree=all,linedraw -n uninstall
I am connected to my VPS (Ubuntu) via SSH.
I use Django, where I process 1000's of images via Django-imagekit ( PIL ). but for some reason, it is not generating an error it just stops/terminates there. it shows all other print commands and everything.
yes, I tried 'try and except' but it doesn't work, it just terminates at 'try' only.
CODE:
from imagekit import ImageSpec
from imagekit.processors import ResizeToFit
class Thumbnail(ImageSpec):
processors = [ResizeToFit(1200)]
format = 'WEBP'
options = {'quality': 90}
Main_image = open('path/to/image.jpg','rb')
Preview_gen = Thumbnail(source=Main_image)
Preview = Preview_gen.generate()
Error while executing the last line
( but works fine on my local machine )
Specs:
Ubuntu Linux 18.04.2
Python==3.6.9
Django==3.0.7
Pillow==8.2.0
psycopg2==2.8.6
psycopg2-binary==2.8.6
django-imagekit==4.0.2
anyone any idea?
error causing image Wallpaper, .jpg, 9600 x 5598
this is the problem for very few images
I haven't been able to figure this out. I'm using qpython3 in android 4.4.2 with a metro pcs Samsung galaxy lite. I do very very little developing in android, so I'm unfamiliar with the differences between android and windows and how I could go about figuring it out.
All I could come up with was what i found on stackoverflow:
import android
url = "http://www.Google.com"
android.Android().startActivity('android.intent.action.VIEW', url)
Which didnt do anything. As soon as you try to run the program, This error pops up and thats all.:
/data/data/com.hipipal.qpy3/files/bin/qpython.sh"/storage/emulated/0/com.hipipal.qpyplus/.last_tmp.py" && exit
s/.last_tmp.py" && exit <
File "/storage/emulated/0/com.hipipal.qpyplus/.last_tmp.py", line 3
android.Android().startActivity('android.intent.action.VIEW', url) ^
SyntaxError: invalid character in identifier 1|u0_a194#gardalteMetroPCS:/ $
Any ideas?
When I tried the code myself, I got the same error. I fixed by changing 's into "s and import android to import androidhelper so code ended up like this and it worked:
import androidhelper
url = "http://www.Google.com"
androidhelper.Android().startActivity("android.intent.action.VIEW", url)