publication

Virtual Environments in Python

Miquel Canal

Friday 25, September 2020
  • Python
  • System Administration

The CheeseShop: Python Package Index (PyPI)

The use of third party libraries and packages is an increase trend on modern software programming. The ability to download and import external libraries in a project makes the software development process much easier. Python is not an exception.

In Python, the place where packages are stored is the Python Package Index.
Secretly known as the CheeseShop. PyPI is a public repository where developers and fetch and publish their packages.

As of today, the PyPI stores more than 2 million packages.

The pip tool

pip is the recommended tool for install packages from the PyPI and it comes installed by default with the >2.7 Python installation.

One important thing to notice when installing packages using pip is to understand where packages are installed. After running a pip command like pip install package1, pip is going to install package1 into the main Python interpreter of your computer. But that is not always the recommended approach.

Installing or updating packages globally may introduce issues in current application as they might be relying on older version of packages. That’s why is recommended to work with virtual environments.

How to create Virtual Environments in Python

Python Virtual Environments are isolated copies of the Python interpreter which can be tied to a particular application. Using Virtual Environments, you can safely install Python packages without affecting other applications. There are two common tools for creating virtual environments: venv used for > Python 3.3 and virtualenv which give support to Python 2.7 applications.

These are the steps for creating Virtual Environments in Python:

  1. Navigate to applications using cd my-path/application.
  2. Run python –m venv venv to create a new python environment naming it venv. The last parameter defines the environment name so you can use any value.
  3. Activate the environment by running: source venv/bin/activate.

After running the activation of an environment, the terminal session is going to be updated and the new venv is going to be used. It is important to notice that the changes to the session are temporary and won’t persist after the terminal window is closed.

References

Environment Variables in Python

Environment Variables in Python

Environment variables are key to Software Development applications. This article reviews best practices for creating environment variables in Python.

PM2 - Production Manager for Node.js

PM2 - Production Manager for Node.js

PM2 is a process manager for node.js applications. A powerful tool that will facilitate common system administration tasks for node apps.

Exploring The Digital Transformation of Energy.

Exploring The Digital Transformation of Energy.

Notes from a webinar presentation about the future of the energy sector. Insights of the digital transformation that the energy industry is currently involved in.

This site uses cookies to ensure a great experience. By continue navigating through the site you accept the storage of these cookies.