kayhoogland / pydata_meetup_pip_demo

This repository contains the code to reproduce the demo I gave during the Pydata Meetup on the 18th of April 2019.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pip require virtualenv trick

Add the following lines to your bash_profile

export PIP_REQUIRE_VIRTUALENV=true

gpip() {
    PIP_REQUIRE_VIRTUALENV="" pip "$@"
}

To see reproduce the demo

Build the docker and run it:

docker build -t <your_tag> .
docker run -p 8888:8888 -it <your_tag>

Run pip freeze to see that your global environment contains jupyter:

pip freeze | grep jupyter

Open another terminal in the docker container and enter the virtualenv:

docker exec -it <docker_container_id> /bin/bash
source venv/bin/activate

Run pip freeze again to see that the virtualenv does not contain jupyter:

pip freeze | grep jupyter

Pip install some packages (not jupyter):

pip install <package_a> <package_b>

Although jupyter is not installed in your virtualenv, you can still use it because it is installed in your global environment. Jupyter will therefore pick your global interpreter with its installed packages. Try for yourself in a notebook:

jupyter-notebook

Of course you can solve this by adding the virtualenv as a kernel to your notebook but in general you do not want to pollute your global environment to prevent weird dependency errors.

About

This repository contains the code to reproduce the demo I gave during the Pydata Meetup on the 18th of April 2019.

License:MIT License


Languages

Language:Shell 52.1%Language:Dockerfile 47.9%