Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Created June 9, 2021 17:20
Show Gist options
  • Select an option

  • Save sheldonhull/8a30152274660374c65d51d67a9841c9 to your computer and use it in GitHub Desktop.

Select an option

Save sheldonhull/8a30152274660374c65d51d67a9841c9 to your computer and use it in GitHub Desktop.
[Python 3 Virtual Env Basics] quick example of using python3 venv to install tools and stuff in a self-contained virtual env in the current project directory #python #windows

Getting Started Tips for Windows & Terminal

  • don't use cmd prompt for anything, use PowerShell
  • install latest windows terminal from store, don't use default terminals, they are terrible and less featured.
  • Suggest installing PowerShell 7 as your normal windows base terminal to use.
  • Install Scoop to make this super easy to install. scoop install pwsh
  • Open pwsh (PowerShell 7) as your default in Terminal

Use Py

With windows use py as it picks the right path automatically.

Virtual Env

Isolates your installs to local project directory to avoid conflicts with other projects. Always a good practice.

TIP: Best practice, though takes practice, is to try and use Docker, as it's true containerized experience. Try codespaces (VSCode supported) or GitPod.io (browser based UI) to get started much more quickly.

Create a virtual env (just a folder to store all the tools)

py -3 -m venv venv --copies;

Activate the local env

.\venv\Scripts\Activate.ps1

Upgrade tooling in the virtual directory

py -3.8 -m pip install --upgrade pip

Install a library

pip3 install pandas

Freeze requirements

pip3 freeze > requirements.txt

TIP: Poetry is a wrapper that makes this nicer. Might look at it in near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment