Setting up Python development environment
Install Python
It’s easy to install Python in your system. Nany Linux and UNIX distributions nowaday already include Python. The first thing you may do is checking if Python was already installed in your system.
On terminal (or cmd if you are Windows user), type below command to check:
$ python -V
Python 3.6.5 :: Anaconda, Inc.
If you get some thing like bash: python: command not found when execute above command, you haven’e had Python installed. You need to download and install it. Go to Python download page and chose the most stable version (the versioon that has highest number and isn’t marked as an alpha or beta release) and download it. Since the last version of Python 2 only receive necessary security updates until 2020, it is highly recommended to use Python 3.
Create Python virtual environment
There are some ways to create Python virtual environment
Using virtualenv
virtualenv is a tool to create isolated Python environments. It creates a directory that contains all the necessary executables and doesn’t share those executables with other virtualenv environments.
The first thing you have to do is install virtualenv. If you are on Windows and you installed Python throught install bundle, you already had virtualenv installed on your system. On other hand, you can manually install it using pip
$ pip install virtualenv
Verify that virtualenv is successfully installed
$ virtualenv --version
16.0.0
Suppose your project is located at ~/my-project
Create virtual environment for your project:
$ cd ~/my-project $ virtualenv my-project-envvirtualenv my-project-envcreatesmy-project-envfolder that contains executables,pip. In this case, the name of the virtual environment ismy-project-env. If you would like to put Python library files in current folder(my-projectfolder), you can do it by ignoring the env name parameter$ virtualenv or $ virtualenv .To chose a specific Python interpreter:
$ virtualenv -p ~/python3.6/bin/python3.6 my-project-envUsing virtual environment
You have to activate the virtual environment in order to use it
On Unix system, you can do it using:
$ source my_project/my-project-env/bin/activateOn Windows:
Scripts\activateDeactivate virtual environment
To deactivate a virtual environment, just use
deactivate$ deactivateDelete virtual environment
To delete a virtual environment, just delete the virtual environment folder, in this case, it is
my-project-env$ rm -rf my-project-envOr if you are using Windows, just delete
my-project-envfolder as you did with any normal folder.