Installing Python 3
Using Virtual Environments
It is always a great idea to sandbox your Python installation; and keeping it separate from your System Python . The System Python is the path to Python interpreter, which is used by other modules installed along with your OS.
It’s not safe to install Python Web-frameworks or libraries directly using System Python . Instead, you can use Virtualenv to create and spawn a separate Python process when you are developing Python applications.
The Virtualenvwrapper module makes it easy for you to manage and sandbox multiple Python sandboxed environments in one machine; without corrupting any modules or services written in Python and used by your machine.
Of course, most cloud hosted development environment such as Nitrous or Cloud9 also comes with these pre-installed and ready for you to get coding! You can quickly pick a box from your dashboard, and start coding after activating a Python 3 environment.
In Cloud9, you need to select the Django box while creating a new development environment.
A few shell command examples would follow. If you wish to copy-paste, do note that the
$ sign is a shorthand for the terminal prompt, it’s not part of the command. My terminal prompt looks something like this:
alayek:~/workspace (master) $
ls would look like
alayek:~/workspace (master) $ ls
But, while writing the same in this documentation, I would be writing it as
Getting back to our discussion, you can create a Python 3 interpreter-included sandbox on Cloud9 by running on your cloud terminal:
$ mkvirtualenv py3 --python=/usr/bin/python3
You have to run it only once after creating a new box for your project. Once executed, this command would create a new sandboxed virtualenv ready for you to use, named
To view available virtual environments, you can use
py3 , you can use the
workon command with the name of the environment:
$ workon py3
All three terminal commands above would also work on local Linux machines or OSX machines. These are virtualenvwrapper commands; so if you are planning on using them, make sure you have this module installed and added to
If you are inside a virtual environment; you can easily find that out by checking your terminal prompt. The environment name would be clearly shown in your terminal prompt.
For instance, when I am inside the
py3 environment; I would be seeing this as my terminal prompt:
(py3)alayek:~/workspace (master) $
(py3) in braces! If for some reason, you are not seeing this, even if you are inside a virtual env; you can try doing one of the things mentioned here.
To get out of a virtual environment; or to deactivate one - use the command
Again, this works only with virtualenvwrapper module.
An alternative to using virtualenvwrapper is Pipenv. It automatically creates virtual environments for your projects, and maintains a
Pipfile which contains the dependencies. Using Pipenv means you no longer need to use pip and virtualenv separately, or manage your own
To get started with Pipenv, you can follow this very detailed guide. Pipenv makes it easy to specify which version of Python you wish to use for each project, import from an existing
requirements.txt file and graph your dependencies.
Installing packages using pip(Python Installer Package):
pip3 install <package-name>
pip3 install numpy #example