avatarSumit Kumar

Summary

The provided content details the process of managing Python virtual environments on a Mac using Visual Studio Code, including creation, activation, deactivation, and deletion.

Abstract

The web content offers a concise introduction to Python virtual environments, emphasizing their utility in organizing project dependencies. It guides readers through the process of setting up a new project folder and managing a virtual environment within it using VS Code. The steps include creating a virtual environment named test_venv, activating it with the source command, deactivating it with the deactivate command, and deleting it using the rm command. The article concludes by congratulating the reader on mastering these skills and encourages following the author for more Data Science content, referencing Python and VS Code official documentations as resources.

Opinions

  • The author believes that using virtual environments is a key Python functionality for managing project dependencies efficiently.
  • The article implies that VS Code is a suitable and possibly preferred IDE for working with Python virtual environments on a Mac.
  • The author expresses a didactic approach, aiming to help readers grasp Python basics and potentially benefit from their work by following them for future content.
  • The inclusion of screenshots suggests that visual aids are considered helpful for understanding the steps involved in managing virtual environments.
  • By providing a step-by-step guide, the author assumes that readers will find value in practical, hands-on instructions over theoretical explanations.

Python Basics- create, activate, deactivate and delete python virtual environment via VS-Code (MAC)

This short introduction explores one of Python’s functionalities that allows us to work on different projects by keeping all their dependencies in one place via virtual environments

We will learn this by creating a new project folder and you can implement the same for your relevant projects.

How to create and start a virtual environment(MAC):

1. Create a new folder on your mac and open it via VS Code. 2. Once done open a new terminal on your VS Code.

3. Run the following command: python3 -m venv test_venv (here test_env is the name for our virtual environment) 4. After running it successfully, you should now see some files generated on your left in VS Code. These files should be under a new folder with the same name as your new virtual environment.

5. Congratulations you have now successfully created a new virtual environment on your VS Code.

Moving forward we will now learn to Activate the environment we just created:

To do that we will have to run the following command from the terminal and it should simply activate your virtual environment. Upon successful run you should see the following output.

source test_venv/bin/activate

The brackets at the front indicate that you are now in your newly created virtual environment. You can now use this to install your favorite packages using pip install xyz command.

The command above runs the activate file from folder test_venv/bin. You can also see this file on your VS Code under the newly created folder:

Deactivate the virtual environment:

Simply typethe following command in your VS Code terminal and that should do the trick:

Deactivate

Delete the virtual environment

Type the following command in your VS Code terminal, and that’s it! To confirm, you can check that the newly created folder on your left has also been deleted.

rm -r test_venv

Congratulations you now know how to use virtual environments in python!

I hope this guide helps someone grasp Python basics. If you find my work helpful, please consider following me, as I will be writing more articles on Data Science.

References:

Python and VS Code official documentations.

Python
Basics
Programming
Recommended from ReadMedium