Skip to content

Instantly share code, notes, and snippets.

@shivampip
Last active April 12, 2020 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivampip/1cdef225c054703fdfa7ee0469947e6b to your computer and use it in GitHub Desktop.
Save shivampip/1cdef225c054703fdfa7ee0469947e6b to your computer and use it in GitHub Desktop.
Python Virtual Environment
  • Install virtual env
pip install virtualenv
  • Go to your project directory
cd project
  • Create virtual env
python3 -m venv yourenv
  • Start virtual env
# Windows
.\yourenv\Scripts\activate

# Linux
source yourenv/bin/activate
  • Stop
deactivate

Deployment on different machine

  • On local machine
pip freeze > requirement.txt
  • On target machine, create an empty env
virtualevn --no-site-packages tourenv
  • Now activate newly created env and install from requirement.txt
.\tourenv\Scripts\activate
pip install -r requirement.txt

Venv in Jupyter Notebook

  • activate yuenv
  • Install it
pip install ipykernel
  • Run this comman
ipython kernel install --user --name=yuenv
  • Now open jupyter notebook from the env.
jupyter notebook
  • Once notebook is opened, select kernel> change kernel > yuenv
  • Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment