Skip to main content

Hack to deal with a missing python3 alias on Windows

Project description

python3

Hack to handle a missing alias/symlink, for example when you're on windows or don't want to be bothered

This exists so that the following Makefile command will execute correctly on Windows.

PLATFORM_ARCH := $(shell python3 -c "import platform; print(platform.machine())")

Installation

To get python3 everywhere and python3 means just some random isolated python3

pipx install python3-alias

To get a known version of python3, install into the system or venv.

pip install python3-alias

Motivation

Yes, I know, one solution is for you to personally purchase a Macbook for everyone in the world. Please include me when you do.

Things that don't work

In git bash, this isn't picked up.

alias python3=python

Link python3 to python in bash

ln -s /c/Users/USER/AppData/Local/Programs/Python/Python312/python /usr/bin/python3
# ln: failed to create symbolic link '/usr/bin/python3': Permission denied

Also adding python3=python to this file didn't work.

nano "/C/Program Files/Git/etc/profile.d/aliases.sh"

Also, a shell file named python3 didn't work.

Installing python from the Microsoft Store might work, I didn't try. I'd rather install from python.org.

Redirecting to a different Python

By default the alias forwards to whichever Python launched it (sys.executable). You can override this with environment variables, checked in this order:

Variable Value Effect
PYTHON3_ALIAS_VENV path to a venv directory Activates the venv (sets PATH, VIRTUAL_ENV, unsets PYTHONHOME) and runs its python.
PYTHON3_ALIAS_PYTHON full path to a python.exe Runs that interpreter directly.
PYTHON3_ALIAS_VERSION 3.14, 3.7, etc. Windows: launches via py -X.Y. POSIX: launches pythonX.Y from PATH.

The first one set wins. If none are set, the alias behaves as before.

Examples

# Pin a specific interpreter
PYTHON3_ALIAS_PYTHON="C:/Python314/python.exe" python3 -V

# Use the py launcher to pick a version (Windows)
PYTHON3_ALIAS_VERSION=3.14 python3 -V

# Run inside a venv without sourcing its activate script
PYTHON3_ALIAS_VENV=./.venv python3 -m pip list

Limitations

This alias isn't to replace pyenv, asdf or the like.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python3_alias-1.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python3_alias-1.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file python3_alias-1.1.0.tar.gz.

File metadata

  • Download URL: python3_alias-1.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python3_alias-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e49b3bbb66e4c3d16e5c64812f8f24bb757a669ac03673d8de5d13653c533131
MD5 03ea48cb54d4886a96b2854b65e409a5
BLAKE2b-256 ef4c09ca2a60df9bcc4c949e8247de66c5b730e0577faba766e20e5cfc52dc04

See more details on using hashes here.

Provenance

The following attestation bundles were made for python3_alias-1.1.0.tar.gz:

Publisher: publish_to_pypi.yml on matthewdeanmartin/python3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python3_alias-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: python3_alias-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python3_alias-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1173e9dbff7215b746ab9da3e06fe546026f12e191b94f59a34d68957ce8443c
MD5 ed3ae2cb554821bfea00adc407e49ef3
BLAKE2b-256 dbf07578b6e66c33c53a964ac96cae82810266b6e9cdb3f818f9553f2b1750ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for python3_alias-1.1.0-py3-none-any.whl:

Publisher: publish_to_pypi.yml on matthewdeanmartin/python3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page