tto / docs / macos / python3 pip3 and homebrew

wow, what a mess. i don’t fully understand any of this, but it seems to work.

the issue

so i want to run some python script and it imports modules that i don’t have. usually, i would install them with pip3 install pandas but that doesn’t work, i get this error:

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.

    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:

    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz

easy you think, i just follow the instructions, but no. powershell doesn’t let me do this source path/to/venv/bin/activate it doesn’t seem to work with zsh either.

the fix

i finally understood that this python3 -m venv path/to/venv creates a new folder that contains all the executables, python, python3, pip, pip3. So what i have to do, is this:

python3 -m venv mypython
mypython/bin/pip3 install pandas
mypython/bin/python3 myscript.py

nice, huh?!