DEV Community

radin reth
radin reth

Posted on

1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay