Environment Shenanigans

Yesterday I tried to update this website and got the horrible "bash: /path-to-ariot/env/bin/pelican: /path-to-ariot/env/bin/python: bad interpreter: No such file or directory" error. That can't be right, I thought to myself, and ran:

python --version # latest
pelican --version

This showed me that I hadn't activated the Virtual Environment (in the env/ folder) so it was running the global python and pelican package (which Manjaro, being a Linux distributtion that follows a rolling-release model, updates occasionally).

So, to avoid future mistakes, I uninstalled the global pelican with:

pip uninstall pelican

And re-created/installed everything locally (make sure that the Environment is deactivated first):

python -m venv env
source "env/bin/activate" # an (env) appears to the left
python -m pip install pelican
python -m pip install --upgrade pip # pip tells you to do this
pelican

This almost worked, but gave an "ERROR: Cannot load plugin css-html-js-minify" message. It also reminded me that the pages are in Markdown (md) so I installed the Markdown and the minifying plugin in the local Environment:

python -m pip install Markdown
python -m pip install css-html-js-minify

Then re-ran pelican to see that everything was working. (You can delete these folders to make sure that Python/Pelican regenerate everything):

rm __pycache__ -r
rm output -r # this is what running "pelican" generates

All is working nicely and, not only does Pelican generate everything again, I can have it serve the page and see it locally:

source "env/bin/activate" # an (env) appears to the left
pelican
pelican --listen

Just open up the http://localhost:8000/ or http://127.0.0.1:8000/ link with a browser. Note that the scripts used with this website do a lot of these things but, unfortunately, my setup.sh script did this:

# Install Pelican

pip install pelican
python -m pip install --upgrade pip

Which means it leads to this problem (after an update) as it used the global pip. Be wary of such mistakes dear readers.