DEV Community

radin reth
radin reth

Posted on

Python Virtual Environment

Installation

Using pip

python -m pip install --user virtualenv
Enter fullscreen mode Exit fullscreen mode

Create folder to local python packages

python -m virtualenv venv
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

Install colorama package

pip install colorama
Enter fullscreen mode Exit fullscreen mode

Call colorama

from pip._vendor.colorama import init, Fore
Enter fullscreen mode Exit fullscreen mode

Install python-dotenv package

pip install python-dotenv
Enter fullscreen mode Exit fullscreen mode

Usage

create .env file

DATABASE_CONFIG=my_database_config
Enter fullscreen mode Exit fullscreen mode

In settings.py

from dotenv import load_dotenv
import os

# load all env variables from .env file
load_dotenv()

# print out the value
print(os.getenv('DATABASE_CONFIG'))
Enter fullscreen mode Exit fullscreen mode
python --version
pip --version # */venv/lib/python3.8/site-packages/pip (python 3.8)

python3.8 settings.py
Enter fullscreen mode Exit fullscreen mode

Top comments (0)