Hi, there! This is my first time blogging and I’ve decided to talk about Python tools, which I’ve been using lately. If you have problems dealing with multiple python and pip versions, then this might help you. Notice that when I say multiple versions, it doesn’t mean that you need to have a bunch of them to fit in this case. I currently use versions 2.7 and 3.4.
The hard way
A very common error that shows up many times while installing a module is a lack of permission that you may bypass using
sudo, but you are probably gonna miss this on your first try, as follows:
The example below used to happen often to me. Because it’s common to type
pip to install a module I was tricked by myself once I used
python3 to run the scripts. The thing is that I should have used
pip3 to install a module to my
python3 distribution. It may sound obvious, but I see it happening a lot with other people.
Another point that gets annoying happens when trying to install another version of python, which doesn’t come by default. As I’m using a vagrant box with Ubuntu Trusty64, that comes with python 2.7 and 3.4, I already have what I need.
Suppose we’re installing Python 3.5. Although I’m not showing this one here, there are many chances for you to end up overwritting your python3 binary, or you will have to deal with symlinks to handle both versions. Check out this link. If you decide to take a look at the python docs, you’ll be asked to go to other links. Be careful not to override your python3 binary (see the image bellow). You can also follow the steps above on YouTube. YouTube.
A cleaner path
There is a way of freeing yourself from that hard road. A tool called pyenv gets things really easy. Thanks, Yuu Yamashita. Its purpose of life is to manage python versions. You can seamlessly switch between versions and also install new versions of python, which incentivizes you trying new stuff since you have no headache, or at least almost no headache.
It gets you rid of those permission issues. Pyenv concentrates all python versions in a folder on your home directory, so you are supposed to have full access. Also, you don’t need to care about which pip version you are installing a new module, nor type
python<VERSION>. Once you choose which version of python you want to use, the tool proxies everything you need.
I want to install a python module to my python 3.4.3, so I check my current version and the ones I had installed:
I change it to 3.4.3:
And from now on, my python commands are being tunneled to the correct version.
If I want to install 3.5 version:
For Linux, you can follow pyenv-installer, which recommends:
For Mac, you can use brew:
To be continued…
Here are some benefits I got after adopting this tool:
- I get rid of some environment issues like permissions;
- Wrong pip/python versions when installing new modules;
- Easy installing of new python version;
- Actually installing new versions since this became easy;
- Seamlessly switching between python versions.
If the benefits above fit you, then it is probably worth trying this out. Hope it helps! : )
PS: There is another tool called pyenv-virtualenv that combined with this one make things even better. That’s what Part 2 of this post is gonna be about.