How to create Streamlit apps in virtual environments, using Conda or Venv?

Muted Coding
4 min readApr 7, 2022

--

There are two ways to create virtual environments for Streamlit apps in Python. Why do we need to create virtual environments in the first place?

They are acting like Windows user account, each user has own desktop, user folder and is able to install programs by their own which are different with other users. each user is isolated from each other, they can not access each other’s files, it is secure and uninterrupted. Virtual environments in Python are the same concept, each virtual environment can have different Python package list, even different Python version. For example, developer can have a project running in Python 2.x version and in Python 3.x version with one identical source code at the same time. User can switch between from different environment setting without modifying the source code, it reduces development time consuming significantly.

Which is the recommended virtual environment package then, Conda or Vven?

Conda and Venv

https://conda.io/

https://docs.python.org/3/library/venv.html

Conda is the external package which requires user to install, Venv is the built-in package in Python, no need to install by user.

let’s see how to work with those two packages.

Conda

For windows, download the .exe file and install it.

Next, open windows terminal, type the following command to create a new virtual environment:

First command is to create Conda virtual environment named myEnv1 with latest Python version.

Second command is to create Conda virtual environment named myEnv1 with specified Python version 2.5.

Third command is to create Conda virtual environment named myEnv1 with specified Python version 3.5.

After the new virtual environment is created, type the following command to confirm it, it should appear in the list.

Conda command won’t create any physical folders in current path, it is safe to execute those commands at any desired path.

Check the full command list on conda cheat sheet, https://docs.conda.io/projects/conda/en/latest/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf

Venv

Type the following command to create Venv virtual environment named myEnv1 at current path.

The different with Conda is that Venv command does create a physical folder at current path, make sure executing those commands at desired path.

the Venv command has created a new folder name myEnv1 under current path. Inside the myEnv1 folder, there is another folder called Scripts, it contains activate.bat and deactivate.bat files, those two will enable and disable the virtual environment.

To enable the myEnv1 virtual environment, type the following command, make sure the executing path is correct.

in Conda virtual environment, user doesn’t need to reinstall the Python packages which has been installed globally, but in Venv virtual environment, each new created virtual environment is acting like new fresh installed Windows, user needs to install all the required programs, it seems redundant and easy to forget but highly customizable, it also created extra folders and files under current path.

Therefore, if developer needs to choose which package to create virtual environment, Venv is easy start but redundant, Conda is powerful but easy to maintain afterwards. The winner is Conda, if you like to know more about it, check the official documentation https://conda.io/projects/conda/en/latest/user-guide/getting-started.html .

--

--

Muted Coding

Student of Computer Engineering Technology at Seneca College (2019–2022), Toronto, Canada