Tag: windows

Comparing Python Executable Packaging Tools: PEX, PyOxidizer, and PyInstaller

Reading time: 9 – 15 minutes

Packaging Python applications into standalone executables can simplify deployment and distribution, especially when dealing with users who may not have Python installed or when aiming for a seamless installation experience. Three prominent tools in this space are PEX, PyOxidizer, and PyInstaller. In this post, we’ll explore each of these tools, highlighting their features, how they work, and their pros and cons to help you decide which one suits your needs.


Table of Contents

  1. PEX (Python EXecutable)
  2. PyOxidizer
  3. PyInstaller
  4. Comparison
  5. Conclusion

PEX (Python EXecutable)

Overview

PEX stands for Python EXecutable. It creates self-contained executable Python environments that are runnable on other machines without requiring a Python interpreter or additional dependencies.

Features

  • Self-contained Executables: Packages all dependencies into a single file.
  • Virtual Environment Management: Manages dependencies in an isolated environment.
  • Support for Multiple Python Versions: Can target different Python versions.
  • Reproducible Builds: Ensures consistent builds across different environments.

How It Works

PEX files are ZIP files with a special header that makes them executable. When you run a PEX file, it sets up an isolated environment and executes your application within it. Dependencies are resolved and bundled at build time, ensuring that the executable has everything it needs to run.

Pros and Cons

Pros:

  • Ease of Use: Straightforward command-line interface.
  • Isolation: Avoids conflicts with system-installed packages.
  • Flexible Configuration: Supports complex dependency management.

Cons:

  • Platform Dependency: The generated PEX file is platform-specific. (OS and Python version)
  • Size Overhead: Can result in large executable files due to included dependencies.

PyOxidizer

Overview

PyOxidizer is a tool that produces distributable binaries from Python applications. It embeds the Python interpreter and your application into a single executable file.

Features

  • Single Executable Output: Creates a single binary without external dependencies.
  • Embedded Python Interpreter: Bundles a Rust-based Python interpreter.
  • Cross-Compilation: Supports building executables for different platforms.
  • Performance Optimization: Optimizes startup time and reduces runtime overhead.

How It Works

PyOxidizer uses Rust to compile your Python application into a binary. It embeds the Python interpreter and compiles your Python code into bytecode, which is then included in the binary. This approach results in a single executable that can be distributed without requiring a separate Python installation.

Pros and Cons

Pros:

  • No Runtime Dependencies: Users don’t need Python installed.
  • Cross-Platform Support: Can build executables for Windows, macOS, and Linux.
  • Optimized Performance: Faster startup times compared to other tools.

Cons:

  • Complex Configuration: Requires understanding of Rust and PyOxidizer’s configuration.
  • Relatively New Tool: May have less community support and fewer resources.

PyInstaller

Overview

PyInstaller bundles a Python application and all its dependencies into a single package, which can be a directory or a standalone executable.

Features

  • Multi-Platform Support: Works on Windows, macOS, and Linux.
  • Customizable Builds: Allows inclusion or exclusion of files and dependencies.
  • Support for Various Libraries: Handles complex dependencies like NumPy, PyQt, etc.
  • One-Folder and One-File Modes: Choose between a directory of files or a single executable.

How It Works

PyInstaller analyzes your Python script to discover every other module and library your script needs to run. It then collects copies of all those files—including the active Python interpreter—and packs them into a single executable or a folder.

Pros and Cons

Pros:

  • Ease of Use: Simple command-line usage.
  • Wide Compatibility: Supports many third-party packages.
  • Flexible Output Options: Choose between single-file or directory output.

Cons:

  • Executable Size: Can produce large files.
  • Hidden Imports: May miss some dependencies, requiring manual specification.

Comparison

FeaturePEXPyOxidizerPyInstaller
Single ExecutableYes (but requires Python)YesYes
No Python RequiredNoYesYes
Cross-PlatformYes (build on target OS)Yes (cross-compilation)Yes (build on target OS)
Ease of UseModerateComplexEasy
Executable SizeLargeSmallerLarge
ConfigurationFlexibleRequires Rust knowledgeSimple
Community SupportActiveGrowingExtensive
GitHub ActivityActively maintainedUnmaintainedActively maintained

Conclusion

Choosing the right tool depends on your specific needs and the assurance of ongoing support:

  • Use PEX if you need a self-contained environment for systems where Python is available. Its active maintenance ensures that you can rely on timely updates and community support.
  • Use PyOxidizer if you prefer a single executable without runtime dependencies and are comfortable with Rust. Its growing GitHub activity signifies a promising future and dedicated maintenance.
  • Use PyInstaller if you value simplicity and extensive community support. Its active maintenance status means you can expect regular updates and a wealth of community resources.

References:

OpenSSH public key fingerprint

Reading time: 8 – 14 minutes

Quick and easy, how to get the fingerprint of your SSH RSA key.

# syntax:
openssl pkey -in PATH/PRIVATE_RSA_KEY -pubout -outform DER | openssl md5 -c

# example:
$ openssl pkey -in ~/.ssh/id_rsa -pubout -outform DER | openssl md5 -c
MD5(stdin)= a6:26:23:d9:c1:d3:d5:e5:c0:38:ab:3c:c1:6a:3f:ea

Get the IP address of the WSL2 in Windows 10

Reading time: 6 – 9 minutes

Nothing else than what the title says. Simple PowerShell script for dumping the IP address:

wsl -- ip -o -4 -json addr list eth0 `
| ConvertFrom-Json `
| %{ $_.addr_info.local } `
| ?{ $_ }

Network traffic sniffing: tcpdump on Linux + Wireshark on Windows

Reading time: 11 – 18 minutes

From the Windows box using the CLI console (cmd):

ssh USER@HOST "tcpdump -s 0 -U -n -w - -i NETIF FILTER" | "c:\Program Files\Wireshark\Wireshark.exe" -k -i -

# USER - remote user of the linux box
# HOST - host address of the remote linux box
# NETIF - network interface to snif in the remote linux box
# FILTER - (optional) rules for filtering traffic to capture

Use case:

C:\Windows\System32\OpenSSH>ssh root@192.168.4.74 "tcpdump -s 0 -U -n -w - -i eno2 udp and not port 53" | "c:\Program Files\Wireshark\Wireshark.exe" -k -i -

Let me present a rare use case of this useful trick. I use a QNAP NAS as a gateway in my home network, where I have 5 NICs. So it’s really useful to snif traffic remotly but I have no tcpdump packet in the system. What I did is use tcpdump as Docker container and finally the commands is like that.

# sniffing SIP traffic (port 5060) on interface eth0
# remote linux host (QNAP NAS) use SSH port 55222
# docker container is created and when work is done is removed
C:\Windows\System32\OpenSSH>ssh -p 55222 admin@10.2.0.1 "cd /share/Container/tcpdump && docker run --rm --net=host corfr/tcpdump -s 0 -U -n -w - -i eth0 not port 22 and port 5060" | "c:\Program Files\Wireshark\Wireshark.exe" -k -i -

Personal note:

ssh -p 55222 admin@10.2.0.1 "docker run --rm --net=host corfr/tcpdump -s 0 -U -n -w - -i qvs0 host 10.2.0.177" | "c:\Program Files\Wireshark\Wireshark.exe" -k -i -

Windows 10: Internal Virtual Switch with NAT

Reading time: 11 – 18 minutes

When you are playing with Windows Hyper-V and you want to create a completely virtual internal network with private virtual machines inside your Windows 10 machine virtual switch are mandatory.

Then it’s the time to connect that virtual switch with the host machine using a virtual network interface. All those steps can be done using Hyper-V manager user interface, but you cannot control 100% of parameters like enable, or not, the NAT of the virtual internal network.

Using PowerShell the steps are:

New-VMSwitch -SwitchName NATSwitch -SwitchType Internal
New-NetIPAddress -IPAddress 10.46.1.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
New-NetNAT -Name NATNetwork -InternalIPInterfaceAddressPrefix 10.46.1.0/24

Of course, change “NATSwitch” for your switch name and “10.46.1.1” for the IP address of the host virtual network card. Finally “NATNetwork” is another arbitrary name for referring to the NAT rule, and “10.46.1.0/24” is the network address of the virtual internal host network.

Running the commands looks like:

For removing what you did:

Remove-VMSwitch -Name "NATSwitch"
Remove-NetIPAddress -InterfaceAlias "vEthernet (NATSwitch)"
Remove-NetNAT -Name NATNetwork

In Windows 10 IP forwarding is not enabled and packets between interfaces are not routed. According to the Microsoft forums, you can enable IP forwarding (routing) using the following steps:

Go to Start and search on cmd or command. Right click on either cmd or command then select Run as administrator. At the command prompt type regedit. Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\Tcpip\Parameters\IPEnableRouter setting, right click and select Modify. Change 0 to 1 and exit the editor.

When your back at the command prompt type services.msc and navigate to the Routing and Remote Access service. Right click and select Properties. Change to Automatic and click on Start to start the service.

I had to research a long time until I found all this information, but in my case leverage my proofs of concepts to another level.

Zerotier peers monitored on Windows PowerShell

Reading time: 5 – 8 minutes

No words just a simple an powerful .ps1 script:

while (1) { Start-Process -NoNewWindow -FilePath 'C:\ProgramData\ZeroTier\One\zerotier-one_x64.exe' -ArgumentList "-q","peers"; sleep 5; cls }

Or just a command, even equally useful.

Portable FTP server for Windows

Reading time: 2 – 2 minutes

Usually, simple things are the best, in the case I want to recommend an FTP server for Windows. This is a really simple but super useful FTP server for Windows. I’m using in Windows 10 and it works perfectly. Configuration is done in less than 10″ and installation is not required, I love that. Super portable.

Don’t expect sophisticated options but the most useful and advanced ones are there. If you need something like that my recommendation is:

Quick’n Easy FTP Server Lite by Pablo Software Solutions

Just a summary and extracted from the product webpage this is a summary of features:

  • Simple, intuitive and cool looking user interface, with several pages for managing the users, configuration and security.
  • Easy to setup using the build-in FTP Server Setup Wizard. 
  • Add new user accounts with the User Account Wizard.
  • Support for systems that are a part of a network with a router and/or firewall.
  • Configuration is saved in XML format.
  • Realtime server trace, which displays every command and it’s reply on the screen.
  • Everything can also be logged to a file.

Screenshots are always lovely, some of them are:

[ngg_images source=”galleries” container_ids=”2″ display_type=”photocrati-nextgen_basic_thumbnails” override_thumbnail_settings=”0″ thumbnail_width=”200″ thumbnail_height=”150″ thumbnail_crop=”1″ images_per_page=”0″ number_of_columns=”0″ ajax_pagination=”0″ show_all_in_lightbox=”0″ use_imagebrowser_effect=”0″ show_slideshow_link=”0″ slideshow_link_text=”[Show as slideshow]” order_by=”filename” order_direction=”ASC” returns=”included” maximum_entity_count=”500″]

Finally just say THANKS Pablo for such good job and so useful stuff.

HTTPie – command line HTTP client

Reading time: 4 – 6 minutes

I imagine you are used to using curl for many command line scripts, tests, and much more things. I did the same but some weeks ago I discovered HTTPie which is the best substitute that I’ve ever found for curl. Of course, it’s also available for a lot of Linux distributions, Windows, and Mac. But I used it with docker which is much more transparent for the operative system and easy to update. To be more precise I use next alias trick for using this tool:

alias http='sudo docker run -it --rm --net=host clue/httpie'

Official website: httpie.org

Let me paste some highlights about HTTPie:

  • Sensible defaults
  • Expressive and intuitive command syntax
  • Colorized and formatted terminal output
  • Built-in JSON support
  • Persistent sessions
  • Forms and file uploads
  • HTTPS, proxies, and authentication support
  • Support for arbitrary request data and headers
  • Wget-like downloads
  • Extensions
  • Linux, macOS, and Windows support

From the tool webpage a nice comparison about how HTTPie looks like versus curl.

ngrok – service which solve services behind NAT issues

Reading time: < 1 minute This is another short entry, in this case for recommending a service which we solve typical problem solved using a DNAT. Once we have a service on our laptop, or on a private server and we have to expose that service on the internet for some time or permanently usually we have to go the firewall, or router and create a NAT rule forwarding a port. This is a simple and powerful service which is going to solve that for you. There is a free account for understanding and testing the service, other plans are available and especially affordable for professional requirements.

ngrock.com

I was frogetting to say it’s compatible with Linux, Windows and Mac.

DHCP server for Windows 10

Reading time: 1 – 2 minutes

This is a super useful and simple tool, first of all, let me say thanks to Dani because I found the tool thanks to him. Very often I have the requirement to set up small virtual, real or hybrid networks using my laptop as a server and I had to boot a VM for getting a DHCP server simple to manage and powerful. Now, this is not required anymore because thanks to this tool I found a super small and flexible tool, I can set up all that I need using an INI file or just a wizard. It’s a pleasure and I don’t have to install anything if I don’t want, just a tray icon application is running for allowing me to give the service to my experimental networks.

Those projects that gain my commitment in a second: DHCP Server for Windows

Scroll to Top