Creating virtual environment in text editor for data science application with Python

Menghongpor
3 min readNov 28, 2022

--

Photo by Liam Charmer on Unsplash

Analogy which I would refer to from time to time to explain what Virtual Environment for Python is would be a backpack. Any objects in the backpack could be thought as packages or libraries. You may have different kind of backpack, containing different objects, for different situations you are in (eg. going to school, going on a trip, or going to work). Same as a backpack, Virtual Environment allows us to store all required packages or library we would need for any data science projects we are going to have. In this article, I would like to show to how to set up a virtual environment in Atom, a text editor, in case you would like to build web application for your data science project.

You may have a question like “Why don’t you use Jupyter Notebook”? Jupyter Notebook is great! I can’t deny it. However, it is not really non-coder friendly. From time to time, you will need to communicate your data modeling or data visualization to other stakeholders in your organization. In such a case, one way is to build a web-based application for your data science project through a text editor. However, you will need to set up a virtual environment in the text editor so that you could get access to all the necessary libraries for your project. In this article, I will be talking about how to set up a virtual environment in Atom.

Well, in order to set up a virtual environment in Atom, you will first need to have Atom. I have found this Youtube video, explaining how to install it.

Now let’s get started. First, you should be having the list of packages or libraries which you wish to have in this virtual environment. I have my requirements.txt file, containing all the packages I will use in my project.

Then we are going to use pip to install all of these packages. Go to command Prompt. Then you need to use cd to change the directory to wherever you kept the requirements.txt file, in this example I saved my requirements.txt in Plotly-Dashboards-with-Dash. Then you may start creating a virtual environment, in this example I name it as mydashenv. You can type conda create — name mydashenv python=3.6 into the command line. This means you create mydashenv environment with Python version 3.6. Then click Enter. You should be waiting for a minute or two for it to install.

Next, you should activate mydashenv environment before installing the libraries. You may use the command line, activate mydashenv.

You should be seeing mydasnenv in the parentheses, indicating the environment has been activated. Once this new environment is activated, now it is time to set up the libraries you would use. You can just use pip install -r requirements.txt. Then it will start installing all the libraries you listed in the text file.

That’s it. You have done setting up the virtual environment. When you start working on your data science project in Atom, you may type activate mydashenv in the terminal shell in Atom directly without going to command prompt to activate the environment so that you can use (or import) the libraries you installed.

--

--

Menghongpor

Data Analyst / Data Science Enthusiast / Self-taught Programmer / Entrepreneur