Skip to main content

wslenv

wslenv is a small helper script intended to populate and print environment variables that are useful when running inside WSL (Windows Subsystem for Linux) - especially when those variables are missing.

It detects WSL, prepares distro info, configures interop, and merges the Windows PATH. Optionally, it prepares WSLg-related GUI variables.

At the end, it prints shell-ready export commands for any variables it had to set.

Why you need it

There are situations where you end up inside a WSL distribution without the expected interop variables - for example, when you log into it via SSH.

Install

If you want it only as a program available in your PATH, use pipx:

pipx install wslenv

If you want to have development version:

$ git clone https://github.com/pyhedgehog/wslenv.git
$ cd wslenv
$ pipx install -e .

Usage

Typical usage is to evaluate wslenv output in your shell or in your script (i.e. in ~/.profile:

eval "$(wslenv)"

If you want to skip WSLg variables:

eval "$(wslenv --no-gui)"

What it sets

Core WSL variables

  • WSL_INTEROP - detects the nearest parent WSL interop relay
  • WSL_DISTRO_NAME - uses wslpath -w /
  • WSLENV - gets Windows WSLENV or sets it to empty
  • PATH - merges Windows PATH entries into the Linux PATH (avoids duplicates)

Optional WSLg variables (GUI apps)

When GUI support is detected and --no-gui / --no-wslg is not used:

  • WAYLAND_DISPLAY
  • PULSE_SERVER
  • XDG_RUNTIME_DIR
  • DISPLAY
  • WSL2_GUI_APPS_ENABLED

Notes

The script relies on WSL interop utilities:

  • wslpath
  • wslinfo
  • cmd.exe /c set

TODO

  • Import from Windows variables mentioned in inherited or imported WSLENV.
  • Make OS packages (at least for Alpine).
  • Make minimal version - i.e. without python dependencies (shell or compilable - C/Ninja/Rust/...).

Release files for wslenv 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wslenv 0.1.0
File Size Uploaded
wslenv-0.1.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wslenv 0.1.0
File Interpreter ABI Platform
wslenv-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / wslenv-0.1.0.tar.gz

Download URL wslenv-0.1.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
05811f689b2027cc43f5050970ee6b35a3f355b2c914ed31314ddaf1dd18c3fc
BLAKE2b-256 checksum
How to use checksums
f48da380fc1a7a2986424294e340f00b56b1ae8d445e0eaaed921a223f8a77fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.10 Windows/10

Release files / wslenv-0.1.0-py3-none-any.whl

Download URL wslenv-0.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73d89efbc090e220d0d4d1810c2f9d4ef469f7a85a4e868834e93355bae06af6
BLAKE2b-256 checksum
How to use checksums
4cb5bb52c47561f7e9adcf8f065bf8cd8d5e72dac708d5d34150d25957469a85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.10 Windows/10

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page