Skip to content

Instantly share code, notes, and snippets.

@troyfontaine
Last active March 4, 2024 14:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyfontaine/e1174ffa2140e7d6f092fe0984225a1d to your computer and use it in GitHub Desktop.
Save troyfontaine/e1174ffa2140e7d6f092fe0984225a1d to your computer and use it in GitHub Desktop.
Setting up Aliases for Python on Windows PowerShell

Getting Your Python (Development) On!

Python for Windows is really easy to install-but what if you had started in the world of MacOS/*nix OSes and miss that single command to call Python or Pip? What if you don't have access to modify your environment PATH?

Windows PowerShell has a feature called "Profiles" which allows you to configure your PowerShell in a similar fashion as you could with Bash, Zsh, etc.

Pretty cool huh?

Create a Profile

To create a Profile (if you don't have one already):

New-Item -Type file -Force $profile

Find the Profile Location

To modify your profile, you need to locate it of course-if you're using Visual Studio Code however you can open the file easily by using this command:

code $profile

Add your Aliases

Similar to setting Aliases in another shell, like Bash, you will want to configure them in the profile so they persist each time you close and re-open PowerShell. Please note, the paths below for the Python and Pip executables are only relevant to a single-user install of the Python for Windows application. You will have to figure out where these are on your system as it can vary quite a bit depending on which Python distribution (e.g. Anaconda) you are using and how it was "installed".

Set-Alias python "$HOME\AppData\Local\Programs\Python\Python38\python.exe"
Set-Alias pip "$HOME\AppData\Local\Programs\Python\Python38\scripts\pip.exe"

Close your PowerShell Window

Once you close and re-open your PowerShell window, you're ready to roll, go ahead and type pip at the prompt and see the output!

Enjoy!

@rockyfjord
Copy link

I am just now starting to discover why it's sometimes not a good idea to add certain things to PATH. I'm new to PS, so thank you!

@ramironery
Copy link

Thank you!

@saurabh-kumar88
Copy link

Perfect Solution, saved my hours, Thank you so much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment