What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To capture a Linux VM’s visible desktop with Python, run a screenshot library inside a live graphical session that the Python process can access. For a straightforward X11 capture, use MSS; Pillow’s ImageGrab is a simple alternative, while PyAutoGUI is useful if the same script will also automate mouse and keyboard input. Installing Python or running a VM alone is not enough: the guest needs an active display, and the session, display server and permissions must allow the process to read it.
First check what you want to capture
This guide captures the guest’s displayed desktop or a portion of it—not the hypervisor window, a host desktop, or a webpage rendered by a remote service. Run the Python script inside the guest, under a user/session with access to the graphical display. A VM started without a desktop, or a script launched as a service without the desktop session’s environment, may have no screen available to capture.
The examples below are most predictable in an accessible X11 session. Linux desktops may instead use Wayland, and compositor permissions and VM display configuration vary. None of the libraries below guarantees capture on every Wayland desktop or headless VM; verify the actual guest session.
Inspect the session environment
From a terminal opened in the guest desktop, check the display variables:
#1 Best Overall
- Intel Core i5-1335U Processor (12M Cache, 12 Threads, up to 4.6 GHz) - 256GB Solid State Drive - 16GB DDR4 SDRAM
- 15.6" FHD (1920x1080) Non-Touch Anti-Glare Display - Intel UHD 620 Integrated Graphics - Stereo Speakers
- 720p HD Webcam with Privacy Shutter. Integrated Microphone - Intel Dual Band Wireless-AC (2x2) 8265, Bluetooth Version 4.2
- I/O Ports: 2x USB 3.0, 1x USB 3.1 Type-C 3.1, Headphone/Mic Combo Port, 4-in-1 Card Reader, HDMI, Kensington Mini-Lock Slot
- Linux Mint (Cinnamon) 64-Bit - Keyboard with Full NumberPad - Fast Charging
echo "$XDG_SESSION_TYPE"
echo "$DISPLAY"
echo "$WAYLAND_DISPLAY"
XDG_SESSION_TYPE commonly indicates whether the login session is X11 or Wayland. MSS uses DISPLAY by default on Linux. An empty DISPLAY when launching Python from a background service is a sign that it may not be connected to the desktop display. These values are diagnostic clues, not a guarantee that capture permissions are in place.
Recommended starting point: capture with MSS
MSS is a practical choice when you may need a particular monitor or screen region, or want image data for further processing. Its documented Linux usage supports saving a screenshot directly:
import mss
with mss.MSS() as sct:
sct.shot(output="screenshot.png")
Save this as capture.py and run python3 capture.py from the guest’s graphical session. If it succeeds, screenshot.png is written to the current working directory. Install MSS using the package method appropriate to your environment and Python setup; the cited usage documentation describes the API, not a universal distribution-specific installation command.
On Linux, MSS selects the display from DISPLAY by default. It also allows a display to be selected explicitly, which can help when the process has access to a non-default X display. The exact display string depends on the guest session; do not guess one. Consult the MSS usage documentation for the supported API and display configuration.
Capture a monitor or region
For processing rather than just saving, call grab() with a monitor or region and pass the returned image data to an image library as needed. MSS documents monitor selection and region capture, including examples in its examples. Inspect the monitor information exposed by MSS before choosing an index: monitor numbering and dimensions depend on the displays presented to the guest. A region must use coordinates and dimensions that fall within the intended display.
Rank #2
- Intel Core i5-10210U (up to 4.2GHz) - 1TB PCIe NVMe + 1TB HDD - 32GB DDR4 SDRAM
- 17.3" HD+ (1600x900) Display, Intel UHD Graphics 620
- Built in HD 720p Webcam with Microphone - Bluetooth Version4.2
- I/O Ports: 2x USB 3.1 (Data Only), 1x USB 2.0, 1x HDMI, 1x Headphone/Microphone Combo Jack
- Linux Mint Cinnamon 64-Bit - 6-Row Keyboard w/ Full Numberpad
MSS documents xshmgetimage as its default and fastest Linux backend, with a fallback to xgetimage when MIT-SHM is unavailable; its documentation notes remote SSH display cases among examples where shared memory may not be available. It describes xlib as legacy. This backend behavior is not a controlled comparison with other packages and does not establish capture speed in every VM or remote configuration.
Alternative: use Pillow ImageGrab
If the script only needs a screen image, Pillow’s ImageGrab.grab() provides a compact option. It returns an image that can be saved to a file:
Free tools Windows power users keep installed
One-click scans. No signup required.
from PIL import ImageGrab
image = ImageGrab.grab()
image.save("screenshot.png")
To capture a bounding box instead of the whole screen, supply the desired box to grab(), using the coordinates and dimensions documented for the installed Pillow version. See the ImageGrab reference for the API.
On Linux, Pillow may try gnome-screenshot, grim or spectacle if the default X11 display does not return a snapshot and those utilities are installed. This is a conditional fallback, not a promise that a particular compositor or VM permits screen capture. Check the reference for the conditions and behavior relevant to your setup.
Alternative: use PyAutoGUI when automation is part of the job
PyAutoGUI’s screenshot function returns a Pillow image and can save it directly while returning the image:
Rank #3
- [ULTRA-RUGGED DESIGN] MIL-STD-810G and IP65 certified. Built to survive 6-foot drops, heavy rain, and extreme vibrations. Features a magnesium alloy chassis with an integrated carry handle for maximum portability
- [4G LTE - WORK ANYWHERE] Integrated 4G LTE Multi-Carrier Mobile Broadband. Stay connected to the internet in remote areas or on the road without relying on Wi-Fi or phone hotspots. True mobile freedom for field professionals
- [1200-NIT SUNLIGHT READABLE] 13.1" XGA Touchscreen with CircuLumin technology. At 1200 nits, it is nearly 4x brighter than a standard laptop, ensuring perfect visibility under direct, intense sunlight
- [LINUX UBUNTU PRE-INSTALLED] Fast, secure, and bloatware-free. Optimized for developers, network engineers, and diagnostic software that thrives in a stable, open-source environment
- [LEGACY SERIAL PORT] Features a native RS-232 Serial Port, HDMI, and USB 3.0. Essential for connecting directly to industrial machinery, CNCs, and automotive diagnostic tools without unreliable adapter
import pyautogui
image = pyautogui.screenshot("screenshot.png")
Choose it when the script also needs PyAutoGUI’s GUI automation, rather than adding automation solely to take a screenshot. Its documentation specifies Pillow and, on Linux, the scrot command for screenshot capture. Check that these dependencies are installed for the guest distribution and the package versions you use. See Screenshot Functions and the PyAutoGUI cheat sheet.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Choose the library that fits the VM
| Choice | Best fit | What to verify |
|---|---|---|
| MSS | Saving a screenshot, selecting a monitor or region, or working with captured image data. | Accessible Linux display; default display comes from DISPLAY. Consult MSS documentation for display selection and backend behavior. |
| Pillow ImageGrab | A direct screen image or bounding-box capture with Pillow’s image object. | Accessible display. Its Linux screenshot-utility fallbacks are conditional on the documented circumstances and installed utilities. |
| PyAutoGUI | Screenshot capture in a script that also performs GUI automation. | Pillow and the documented Linux scrot dependency, plus access to the graphical session. |
The cited documentation does not provide a controlled cross-library performance test. Pick based on display access, dependencies already available in the guest, need for region/monitor selection, and whether automation is also required.
When the script runs headlessly or outside the desktop session
A screenshot library reads a display; it does not create one. If the VM boots without a graphical desktop, there may be no visible guest screen for these APIs to capture. Likewise, launching a script from cron, a system service, a container, or a separate SSH login does not automatically give it the logged-in desktop’s display connection.
- For a desktop capture, run the script from a terminal in the guest’s active graphical session first.
- If you must launch it elsewhere, determine which display session the target desktop uses and whether the process has its display variables and authorization. Avoid copying a guessed
DISPLAYvalue or weakening access controls as a generic fix. - If the session is Wayland, confirm that your compositor and capture mechanism permit the operation. The available library documentation does not establish one universal Wayland fix.
- If you actually need an image of a webpage—not the VM’s desktop—use a browser screenshot service instead of a desktop capture library.
Troubleshoot black, missing or failed screenshots
The output file is missing
Check the process’s current working directory and confirm the script completed without an exception. Save to an explicit writable path if needed, such as /tmp/screenshot.png. A path issue is separate from display access.
The image is black, blank or not the desktop you expected
Confirm a graphical desktop is visibly running in the guest, then run the script from that session. Check whether the session is X11 or Wayland and inspect DISPLAY. Also investigate compositor permissions, session ownership and the VM’s display configuration. The available documentation does not identify one fix that applies across hypervisors and Wayland compositors.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #4
- THE POWER TO STAY PRODUCTIVE – Looking to make your everyday work and home life more manageable without breaking the bank? The Lenovo V15 Gen 4 offers long-term reliability with top-of-the-line features to make you your most productive self.
- CRUSH YOUR TO-DO LIST – The AMD Ryzen CPU pairs quiet performance and enhanced operating power to crush your high-demand workday. It optimizes performance and allows for seamless multitasking.
- TRUE-TO-LIFE VISUALS – The 15.6” FHD IPS display is anti-glare with 300 nits brightness to see your best outside or in. Its 88% screen-to-body ratio makes viewing detailed applications like spreadsheets a breeze.
- SEAMLESS COLLABORATION – Lenovo Smart Appearance enhances your camera effects to protect your privacy and to make you the focus of every video conference. Intelligent noise cancelation minimizes distraction and Dolby Audio provides an elegantly sonorous experience.
- BUILT TO WITHSTAND – Built for military-grade toughness, the V15 Gen 4 is tested to withstand harsh temperatures, pressure, humidity, vibrations and more. Keep your work safe from the board room to your living room and everywhere in between.
MSS cannot find or open the display
Check that DISPLAY is set for the process and points to the intended accessible X display. MSS defaults to the display indicated by that variable; an explicit display can be selected when appropriate. A value present in one shell does not prove a different service or user has authorization to access it. See the MSS usage guide.
Pillow does not capture through the default X11 path
Pillow’s Linux fallbacks to gnome-screenshot, grim or spectacle are conditional. Check the ImageGrab documentation for when they may be tried and whether the relevant utility is installed. Installing a fallback command alone does not guarantee that the compositor allows capture.
PyAutoGUI reports a missing dependency
Verify Pillow and scrot are installed in the same guest environment and available to the Python process. A package installed on the host, in another virtual environment, or under another Python interpreter will not satisfy the guest script’s dependency.
MSS behaves differently over SSH or a constrained X connection
MSS documents fallback from its shared-memory xshmgetimage backend to xgetimage when MIT-SHM is unavailable, including some remote SSH display cases. This explains a documented fallback path, but does not resolve missing X access or guarantee identical performance.
Performance, reliability and output considerations
Capture success depends first on the guest session and display permissions. For repeated captures, reuse a single MSS context as in the example rather than treating each call as an unrelated setup, and write output somewhere the process can access. Large desktop dimensions and frequent captures mean more image data to process and store; choose a region when a full-screen image is unnecessary. The cited materials do not establish a general speed ranking among MSS, Pillow and PyAutoGUI.
Best Value
- Powerful Linux Laptop: This IdeaPad Slim 3 Laptop comes pre-installed with Ubuntu Linux, offering fast performance, robust security, and a clean, user-friendly experience. Enjoy full customization, seamless hardware compatibility, and access to thousands of open-source apps. Whether you're working, creating, or coding, it's built to keep up with everything you do.
- A Multitasking Master: The latest AMD Ryzen 7 5825U processor (up to 4.5 GHz) delivers powerful performance with 8 cores and 16 threads for smooth multitasking. Integrated AMD Radeon Graphics provide crisp visuals for streaming, browsing, photo editing, and casual gaming. With smart machine intelligence, it adapts to your needs for a fast, responsive experience.
- 15.6" Full HD Display: The IdeaPad Slim 3 boasts an 88% screen-to-body ratio for a floating, edge-to-edge visual experience. TÜV Low Blue Light certification reduces eye strain, making it perfect for long work or study sessions.
- Military-Grade Durability: The smart IdeaPad Slim 3 combines portability and durability, letting you work, study, and play on the go. With a profile 10% slimmer than the previous generation, it's lightweight yet military-grade rugged, ready for anything, anywhere.
- Versatile Connectivity: Enjoy the security of a built-in webcam with a privacy shutter. Connect effortlessly with multiple ports: 2x USB A, 1x USB C, 1x HDMI, 1x SD Card Reader, 1x Headphone/Microphone combo. Bundle comes with Stylus Pen, 256GB Portable SSD and 5-in-1 Docking Station.
Use PNG in the examples for a lossless screenshot and broad image-tool compatibility. If storage or transfer size matters, convert the returned image to an appropriate format using the image library’s documented options. Keep capture and file-writing errors distinct when diagnosing failures: a blank capture suggests display/session access, while a write exception may simply mean the destination is not writable.
Or skip the browser setup
For a webpage screenshot, rather than the Linux guest’s visible desktop, ScreenshotNeo provides a website screenshot API and MCP server. It cannot capture a VM desktop session. A single GET request can return a webpage screenshot or PDF; here is the cURL form:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Before capture, it can accept cookie/consent banners like a visitor and remove known consent platforms, newsletter popups and chat widgets; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.
Frequently Asked Questions
Can a Python script capture a screenshot if the Linux VM has no desktop installed?
Not with these desktop screenshot APIs by themselves. They capture an accessible display and do not create a graphical session.
Can ScreenshotNeo capture the VM’s guest desktop?
No. ScreenshotNeo captures webpages; use a library inside the guest to capture its visible desktop.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

