Bobcares

Activate Virtualenv Digitalocean | Explained

by | Sep 17, 2022

Let us take a closer look at how to Activate Virtualenv Digitalocean with the support of our DigitalOcean Managed Services at Bobcares.

What is Virtualenv Digitalocean?

 

An environment in Python is a folder (directory) that contains everything that a Python project (application) requires to run in an organized, separate manner. When launched, it automatically includes its own Python interpreter – a clone of the one used to generate it – as well as its own pip.

Activate Virtualenv Digitalocean

Virtualenv solves a variety of issues, including:

 
  • Making a new, separate environment for a Python project
 
  • The ability to download packages without requiring administrative or sudo capabilities.
 
  • Simple application packaging
 
  • Creating a list of dependencies for a single pip-created project.
 
  • Using a requirements file prepared with pip, we can easily retrieve the de</mark>pendencies.
 
  • Giving way to cross-system portability
 

Regardless of how many Python projects we have, working using virtualenv is the recommended method. It is incredibly simple to use and a fantastic tool to have on hand. When used with pip, it truly works wonders.

 

Install and activate virtualenv on digitalocean

 

We can have a separate location on the server for Python projects by using virtual environments. We’ll use venv, which is part of the standard Python 3 library and can be installed by typing:

 
sudo apt install -y python3-venv
 

Create a Virtual Environment

 

Using the pyvenv command, we can establish a new environment. In this case, we’ll refer to the new environment as my env.

 
python3 -m venv my_env
 

Activate Virtual Environment

 

Use the command below to activate the environment, where my env is the name of the programming environment.

 
source my_env/bin/activate
 

The command prompt will be prefixed with the environment name as shown below:

# (my_env) [root@layerstack environments]#
 

Test Virtual Environment

 

Start the Python interpreter by typing in the following:

 
python
 

When we get the following output, we know we’re in the interpreter:

 
Python 3.8.2 (default, Mar 13 2020, 10:14:16) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
 

Now, write the classic Hello, World program using the print() function:

 
print("Hello, World!")
 
Output:
Hello, World!
 

Deactivate Virtual Environment

 

Terminate the Python interpreter:

 
quit()
 

Then, quit the virtual environment by typing in the following code:

 
deactivate
 

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

 

To sum up, from this article you have learned how to install and Activate Virtualenv Digitalocea including creating and quiet virtual environment.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.