Create your own VE with Python
pc: pexels

Create your own VE with Python

VE (virtual environment) could really help you in executing your products or services with different requirements. You joined a new job where they are still using Python 2.0. If you know how to create a virtual environment, it will be much easier for you to do things straight away.

Creating a virtual environment is pretty easy and straight forward. You can create a virtual environment easily using the library called virtualenv. To install the library go to your terminal and type

pip install virtualenv

To create a virtual environment in Python3, first, choose the folder where you would like to create the virtual environment. Then using your command prompt, go to your directory (folder) and write virtualenv "name of the environment" as an example:

virtualenv environment name

It will take some time and create a virtual environment for you. For example, if I would like to create a virtual environment called Venv at the location C:\Users\Sam\Environments, in the command prompt I will write,

<base> C:\Users\Sam\Environments\virtualenv Venv

and it will create a virtual environment named "Venv" for me.

Now you have created the virtual environment successfully, how to activate it? To activate the virtual environment, go to your Venv directory, look for Script folder and write activate. You can use cd .. to move around different environments.

<base> C:\Users\Sam\Environments\Venv\Scripts\activate

It will activate the virtual environment for you. How do you know that it has been activated? In the command prompt, you will see, in place of <base>, it will be <Venv>

<Venv> C:\Users\Sam\Environments\Venv\Scripts\

To deactivate the virtual environment, just write deactivate

<Venv> C:\Users\Sam\Environments\Venv\Scripts\deactivate

The above method only creates the virtual environment in Python 3. If you would like to create the virtual environment for Python 2, you need to install python 2 separately first and then follow similar steps.

Here is one of the many methods for it. To install python 2, go to your anaconda prompt and type,

conda create --name py2 python=2.7

Here py2 is the name of the environment (you can give any name of your choice). It will install the python 2.7 version. After installing it, find out where it has been installed. Usually, for anaconda, it gets installed in envs folder under Anaconda3. Noted down the path of the folder. As an example path: 'C:\Users\Sam\Anaconda3\envs\Py2\python.exe'

Now go to your folder where you want to create virtual environment and write in one line virtualenv -p "the path"

<base> C:\Users\Sam\Environments\Python2\ virtualenv -p C:\Users\Sam\Anaconda3\envs\Py2\python.exe Venv2

It will create a Python 2 virtual environment for you.

Now you have found out the way to install the virtual environments. One thing is still missing, especially for folks who are very interested in data science, machine learning, etc. and that is how to use the newly created virtual environment in Jupyter notebook? Well, there is a way. Go to your virtual environment, activate it and then write pip install iPykernel. After you have installed the package, you need to connect it with the Jupyter notebook. For this, you need to write the following

pip install ipykernel
ipython kernel install --user --name=Venv

here Venv is the name of the virtual environment. That's it. Now when you create a new file in Jupyter, click on new and you will see Venv in the dropdown menu.

That's it for now. Hope it will help you. If you know someone who could get benefit from it, please share it with them and let me know your thoughts.

Sayantan Mukherjee

Battle-hardened Technologist | Hands-on programmer | Still Learning

4 年

Don't rely on virtual env for deploying python. Venv are quite useful for quick developments/test. For deployment I will prefer containers.

要查看或添加评论,请登录

Soumyabrata Roy的更多文章

  • Offline BI Dashboard You can send through Email

    Offline BI Dashboard You can send through Email

    Today data is the new oil. People who have data are always is in a competitive advantage over their peers.

  • Diabetes Predictor ML App

    Diabetes Predictor ML App

    Hello all. just see the diabetes predictor application in action.

  • What is Data Analysis? My intake from Google Data analysis course

    What is Data Analysis? My intake from Google Data analysis course

    I got the opportunity to take the new google data analytics course. This is the gist of my understanding of the data…

  • Some cool Data Science tricks, most of Pandas

    Some cool Data Science tricks, most of Pandas

    This week I have learned quite a few data tricks which I would like to share with you all. It might help you in your…

  • Creating Currency Converter | Python

    Creating Currency Converter | Python

    A currency converter could be really useful to anyone who needs to monitor currency fluctuations and it's measuring. In…

  • Automate the Google search using Python

    Automate the Google search using Python

    Whenever we need help, we take simple help from Google. With 5.

    2 条评论
  • Tableau the Best Tool for Data Visualization

    Tableau the Best Tool for Data Visualization

    We all know the data is important. Today millions of data are created every second and if we can analyze it, use it for…

    2 条评论
  • My Data Science Week 8

    My Data Science Week 8

    Ok. now you know the theory behind Binomial distribution, Poissons distribution from my previous article.

  • My Data Science Week 7

    My Data Science Week 7

    Hi There. In this week you will find more about the different distributions in Probability and about the…

  • My Data Science Week 6

    My Data Science Week 6

    Hi there, how are you doing today? Today I'm going to tell you more about the data and how you can use it to find out…