Code Python on ArchLinux

Published Jan 16, 2018
Code Python on ArchLinux

ArchLinux is fantastic,because you can use Python3 as your default Python version when you’re coding without consider to much about how to install a library in Python3 otherwise Python2.

What’s more, when I type python in CLI.

$ python

It shows in Python3 version even if there’re many processing and software dependence based on python2.That make me feel grateful. I want to say ArchLinux combine Python in a awesome elegant way truly.

But how we deal the problem that if we want to use a diverse verison python in Arch or other Unix/Linux platform.

There is a marvelous tool can solve these problems and even do more for all of us — virtualenv.

Virtualenv is just like a sandbox. You can manage your project’s library and ‘change python verison’ by using it.

No more nonsence,let’s go to install it at first.

$ sudo pip install virtualenv

Make sure you have setup pip at first. In ArchLinux you can use this command directly if I don’t make a mistake of my memory.

Whether you’re using ArchLinux,Debian,OS X ,you can use this tool to change your python verison even thought you installed it in python2.

For example,if I want to code a program on ArchLinux by using Python2,such as flask,Django,while you know.

You can do like this:

virtualenv -p /usr/bin/python2 yourenv
source yourenv/bin/activate
pip install package-name

It’s important to find out the path of your python2.(It also means if you want to code in python2 helped by virtualenv,you need install python2 at first)You can use command which to help you.

$which python2

$which python3

Because in different platform or using diferent way to install Python(such as brew,apt-get), the path can be differenet.

In other platform,if you want to using Python3 and enjoy pip you can do like this:

virtualenv -p /usr/bin/python3 yourenv
source yourenv/bin/activate
pip install package-name

That’s all,thank you for reading and hope you to enjoying coding in Python or using ArchLinux.

Discover and read more posts from Jimmy liu
get started