ELI5: Python Virtual Env
1 min readAug 8, 2021
The instructions below are for mac
It’s recommended to use python virtual environment when working on python project. Couple of important reasons
not populate the default python (yes, most operating systems installation come with python builtin). this can potentially break programs that depend on python
to isolate your project with correct versions of libraries/dependencies
python -V
brew install pyenv
pyenv install 3.8.2
pyenv local 3.8.2
# should return 3.8.2
python -V
mkdir pydo
python -m venv venv380
source venv380/bin/activate#ready for dev# or try oneliner have `venv` automatically bring `pip` and `setuptools` to their latest versions python -m venv --upgrade-deps env/source venv380/bin/activatepython -m venv env
source env/bin/activate
pip install -r requirements.txt && python setup.py install
pyenv rehash # rehash pyenv shims (run this after installing executables)# to run a test
pytest path_to_test_file -k 'run_this_test_case_only'alias venv='python -m venv env'
alias actv='source env/bin/activate'
alias dctv=deactivate
alias pyclean='find . -type f -name '\''*.py[co]'\'' -delete -o -type d -name __pycache__ -delete -o -type f -name '\''.coverage.*'\'' -delete'