/*Font style and formatting for LibGuides*/ Skip to Main Content

Introduction to Python

Getting set up for Python programming

Virtual Environments

Virtual environments are sandboxes that allow you to create a fresh installation of Python (and associated modules and packages) for each project you start. This may seem like an unnecessary step when you're just starting out, but as you begin to work on multiple projects, using virtual environments can help you maintain a clean workspace. When virtual environments are not used, Python packages with different dependencies can cause problems that can prevent you from working on your projects until they are resolved.

Setting up a virtual environment now will save you a great deal of time and trouble later. Fortunately, setting up virtual environments in Anaconda is straightforward.

Unlike some other tools for managing virtual environments, Anaconda allows you to select which version of Python to use for each new virtual environment. This is a huge advantage when it comes to working with modules that were developed using older version of Python, which may not be compatible with newer versions.

Find the Environments Tab in Anaconda

On the left side of the Anaconda Navigator window, click the “Environments” tab. Here you will find a list of the virtual environments you have available for use in Anaconda:

Location of Environments tab in Anaconda Navigator interface.

If this is your first time using Anaconda, you will only see one environment listed: "base(root)". On the right side of the page there is a list of all the packages installed in that environment.

Create a New Environment

Click the “Create” button at the bottom left of the page. A dialog box will appear, asking you to name your new environment. Type in whatever name you think is appropriate for your project. You can select which version of Python you want to install. Generally speaking, the latest version is best, but some projects may have dependencies that require the use of earlier versions of Python. Then, click “Create.”

Popup for "Create new environment" in Anaconda Navigator

Anaconda Navigator will take a moment to create the new environment and load in the default packages. You will see that the list of installed packages is much shorter in the new environment than in the base (root) environment.

Install Jupyter

Once Anaconda finishes setting up the environment, go back to your Home page by clicking the Home icon at the top left of the page. Find the application widget for “Jupyter Notebook” and click “Install.” Anaconda will begin installing Jupyter Notebook. JupyterLab should install automatically alongside Jupyter Notebook, but if it does not, you may have to repeat this process for JupyterLab.

Home screen in Anaconda Navigator, showing installed applications.

Now, go back to the Environments tab. You will see that there are now many more packages installed in your newly created environment, but there are still a few we need to install for a data science/data analysis project. Packages and modules may be installed via command line; we'll cover that on the next page.

Virtual Environments Outside Anaconda

There are several Python packages that allow you to create and run virtual environments. The modules venv, virtualenv, and Poetry are popular choices.