Sometimes we have more than one project running in one machine and sometimes they require same package with different version. In that case, installing package with one version will crash other project that require different version of the package. And that is why we need Virtual Environment.
Virtual environment is tool that creates separate environment for separate project. virtualenv is Python module that allows to create Virtual Environment for Python projects which could break system tools or other projects. All Python packages are called as Python module.
This article will share you details how to create virtual environment for python.
You need to have non-root user account logged in with sudo privileges to set up on your server. Pip installed which will install Python modules. We will install Python3 modules in this article.
Open the terminal by using the CTRL+ALT+T
keyboard shortcut or by running a search in Ubuntu Dash. Now run any of the following command to install virtual environment.
sudo apt-get install python3-virtualenv
or
python3 -m pip install virtualenv
or
pip3 install virtualenv
You can check environment version by running following command:
virtualenv --version
Run any of the following command to create virtual environment:
python3 -m venv newenv
or
virtualenv -m newenv
This will create Virtual Environment folder named newenv. This folder is the Virtual Environment and all Python modules for this environment will install in this folder.
Use this command to activate virtual environment
source newenv/bin/activate
This will prefix environment name in Terminal window when you activate Virtual Environment like this:
(newenv) [email protected]:~#
When you have Virtual Environment activated and you install new Python modules, it will be installed for that specific environment only. It will not affect Python modules installed Globally. Install Python modules with Pip with running command:
pip3 install <package_name>
If you need to deactivate environment, run bellow command:
deactivate
So now you have created virtual environment named newenv. You can create as many Virtual Environment as you want with any name.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Remove a Package from Laravel using Composer
Composer is dependency manager for PHP p...How to get form data in jQuery using serialize and serializeArray Method
jQuery serialize() method used to create...How to get single value from an array in PHP
Use the Array Key or Index If you wan...Login with Facebook in Angular9 using Firebase
I am going to talk about How you can&nbs...React use one Component to many HTML Fragments
A react component is used to return mult...