Most of the time when we are working on Python projects we end up installing different packages/dependencies that we need within a given project. By default, these packages are installed on a default directory making the system-wide available for all the projects you run. As you develop more and more projects your packages may be updated in a way that it breaks the functionality of packages for the previous projects and soon or later your projects can’t compile anymore or at worst the kernel ‘keeps dying’ in Jupiter notebook like it happened to me at first.
To avoid all this problems we need a virtual environment.
This is a feature in Python (also integrated to most IDEs) which allows you to create projects in such a way that each project has its own dependencies.
Lets go ahead and see ho create and work with virtual environment.
Install pip.
For windows: No need to install if you are running Python 3.4+ and Python 2.7.9+ because these versions comes with pip
pre-installed.
For Linux (Debian/Ubuntu): run
apt install python-pip
for Python 2
or
apt install python3-pip
for Python3
**pip**
install you may need to update.Windows: python -m pip install -- upgrade pip
Linux: pip install --upgrade pip
**virtualenv**
for windows.Windows: python3 -m pip install virtualenv
We will not install virtualenv
on Linux because we will use venv
function to create virtual environment.
Simply run pip3 install --user ipykernel
#virtual-environment #python #python3 #pip #jupyter-notebook