When Installing reportlab in Python on Alpine, It Results in "Not a directory: '/dev/null/.reportlab_mods'"

2022-02-04 16:45 (2 years ago) ytyng

When you encounter an error like this:

 File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/var/src/manga-server-django/delivery/models.py", line 464, in <module>
from reportlab.pdfbase import pdfmetrics
File "/usr/lib/python3.9/site-packages/reportlab/__init__.py", line 56, in <module>
_fake_import(os.path.expanduser(os.path.join('~','.reportlab_mods')),'reportlab_mods')
File "/usr/lib/python3.9/site-packages/reportlab/__init__.py", line 28, in _fake_import
sys.modules[name] = m.load_module(name)
File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1034, in load_module
File "<frozen importlib._bootstrap_external>", line 859, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 851, in exec_module
File "<frozen importlib._bootstrap_external>", line 987, in get_code
File "<frozen importlib._bootstrap_external>", line 1044, in get_data
NotADirectoryError: [Errno 20] Not a directory: '/dev/null/.reportlab_mods'

Upon closely examining the error message, you will notice that:

os.path.join('~','.reportlab_mods')

is being converted to:

 '/dev/null/.reportlab_mods'

which is causing the error. To resolve this, you need to add a line like:

ENV HOME=/var/app

to your Dockerfile. The directory should be an appropriate one with the necessary permissions.

This issue occurs when running a Python application as a non-root user.

Currently unrated

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011