skeletrex
skeletrex

Reputation: 1

Is there any way to change the name of python when using the terminal

Currently when I need to use python in the terminal or run something with python I need to write "python3 ....." For example "python3 manage.py makemigrations" Is there any way I can rename it to something shorter for simplicity like "py"

Upvotes: 0

Views: 270

Answers (3)

jack
jack

Reputation: 21

Like the first comment, I am also using an alias. However, if you use a dependency manager like Poetry, python works by default when inside your virtual environment. No need to create an alias.

Setting up an alias

  1. Open your zshell or bash profile open ~/.zshrc
  2. Setup your alias in your profile alias py=/usr/local/bin/python3.9
  3. Save and close the file.
  4. Return to your terminal
  5. source ~/.zshrc (or source your bash profile, whichever setup you have)
  6. python

Upvotes: 0

jagamts1
jagamts1

Reputation: 253

If you using Linux or Mac. You can achieve this by using a symbolic link

First, get your python path by using

which python

Then create a symbolic link

ln -s /Users/.virtualenvs/bin/python /Users/.virtualenvs/bin/py

Hereafter just using py will run as python

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 191738

Sure, you can create a symlink in your PATH or alias in your terminal. Do not rename the executable itself...

But some OS prefer you use python3 since python commonly refers to Python 2.x executable, which is end of life, but still exists as a dependency for some programs

Upvotes: 1

Related Questions