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 python3 # /usr/local/bin/python3 which pip3 # /usr/local/bin/pip3
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
.bashrc depending on your environment:
# 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
And you're all done!
pip are both mapped to their 3.x versions,
A collection of quick tips and tricks to level up your coding skills one step at a time.
Mutable default arguments can trip up Python beginners and veterans alike. Here's a quick workaround to deal with them.
Learn the difference between two common ways to access values in Python dictionaries and level up your code today.
When working with files in Python, it's important to ensure that the file is closed correctly. Here are a couple of ways to do that.