Environment Variables in Python
Environment variables are key to Software Development applications. This article reviews best practices for creating environment variables in Python.
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.
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.
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:
cd my-path/application
.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.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.
Environment variables are key to Software Development applications. This article reviews best practices for creating environment variables in Python.
PM2 is a process manager for node.js applications. A powerful tool that will facilitate common system administration tasks for node apps.
Easy steps to configure a Git repository and change the Git user name and email. A review of git's config object and how to retrieve information from a git repository using the git config command.