Bitpath

Lesson 2 · Unit 02

Environments

Virtual environments, node_modules, pinning the language, and "works on my machine"

13 exercisesabout 3 min

What you practise

  • Virtual environments and node_modules, how an import is resolved, pinning the language version, "works on my machine" taken apart

Try a question from this lesson

Pick one

One Python serves the whole machine and holds one version of each library. Project A needs version 1 of a library, B needs version 2. You install 2. What about A?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Virtual environments

A virtual environment is a folder with its own packages and a python that uses them. One per project, so projects cannot fight.

Activating it is no magic: it puts the folder's bin at the front of PATH, so python and pip now mean the copies inside.

shell
python3 -m venv .venv
source .venv/bin/activate
echo "$PATH" | cut -d: -f1

Concept

JavaScript: location decides

JavaScript needs no activation. Packages are installed into a node_modules folder inside the project.

An import of b looks in the node_modules next to the importing file, then in the parent folder's, and so on up to the root. Where the file sits decides what it gets, not PATH.

Concept

Pin the language too

The lockfile pins libraries. The language itself needs a pin as well.

A small file in the repository names the version (.nvmrc, .python-version). A version manager reads it and puts that version first on PATH, and CI reads the same file. Everyone runs the same interpreter.

9 more exercises in the app

  • 5× multiple choice
  • 1× true or false
  • 1× type the answer
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy