2023-11-06 pyenv, venv and weasyprint

I’m not a big Python-using programmer and so I lack the experience to handle unexpected issues. Yesterday I ran into something I think is worth documenting for myself. Perhaps I’ll run into it in another year’s time.

The symptom I noticed yesterday was that weasyprint wouldn’t hyphenate the PDFs I was generating. I suspected that it might be related to the recent switch to Debian 12.

switch to Debian 12

I installed weasyprint again:

sudo apt install weasyprint

That seemed to have no effect. So I decided I’d like to install weasyprint from PyPI again.

pip3 install weasyprint

This resulted in a strange error:

Could not fetch URL https://pypi.org/simple/weasyprint/: There was a
problem confirming the ssl certificate:
HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded
with url: /simple/weasyprint/ (Caused by SSLError("Can't connect to
HTTPS URL because the SSL module is not available.")) - skipping

https://pypi.org/simple/weasyprint/:

It took me a while to understand what this was about.

I rediscovered that I was running pyenv when I tried to verify the Python version I was running:

$ which pip3
/home/alex/.pyenv/shims/pip3

I had installed pyenv so I was using my own self-compiled Python which was in fact missing the SSL library it had been compiled against. I suspect that it’s the same disappearing library that caused me so much headache when I moved to Debian 12: libcrypt1.

@jonny@social.coop helped me realize that uninstalling it all might be the answer.

I wasn't quite sure how to uninstall pyenv. I could uninstall the environment I was using, but it kept listing it as unavailable. Then I remembered why I had installed pyenv in the first place: I had needed a newer Python to install the latest weasyprint! Since I now had a newer system Ptyhon I probably didn’t need pyenv any more and so I deleted what I found in “*/.local” and the line I had added to “*/.config/fish/config.fish” and restarted my shell.

When I tried to install weasyprint using my system’s pip, it warned me about messing up my system’s Python and recommended using a virtual environment. This seems reasonable and so that’s what I did.

sudo apt install python3.11-venv
mkdir ~/.local/weasyprint
python3 -m venv .local/weasyprint/
.local/weasyprint/bin/pip install weasyprint
cd /home/alex/.local/bin/
rm weasyprint
ln -s ~/.local/weasyprint/bin/weasyprint .

And now hyphenation works again!

If you’re curious, there’s a link of posts going into the benefits of weasyprint here: Markdown instead of LaTeX, Writing Markdown, generating PDF, Markdown to PDF.

Markdown instead of LaTeX

Writing Markdown, generating PDF

Markdown to PDF

​#Administration ​#Python ​#Programming ​#Markdown