HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonTip

Set up Python 3 and pip 3 as default

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
defaultandsetpippython

Problem

One of the most common headaches when working with Python is having to remember to use Python 3.x instead of Python 2.x. Luckily, it's really easy to setup Python 3 and pip 3 as the defaults. You first need to figure out where each one is installed using the which command:
Make a note of each response, so that you can add the paths as aliases to your shell environment's configuration file. Then, you can use echo to add a line for each one to either .zshrc or .bashrc depending on your environment:
And you're all done! python and pip are both mapped to their 3.x versions,

Solution

which python3   # /usr/local/bin/python3
which pip3      # /usr/local/bin/pip3


And you're all done! python and pip are both mapped to their 3.x versions,

Code Snippets

which python3   # /usr/local/bin/python3
which pip3      # /usr/local/bin/pip3
# Linux or other bash environment
echo "alias python=/usr/local/bin/python3" >> ~/.bashrc
echo "alias pip=/usr/local/bin/pip3" >> ~/.bashrc

# Mac OS or other zsh environment
echo "alias python=/usr/local/bin/python3" >> ~/.zshrc
echo "alias pip=/usr/local/bin/pip3" >> ~/.zshrc

Context

From 30-seconds-of-code: setup-python3-pip3-as-default

Revisions (0)

No revisions yet.