Python plugin EnvironmentError: [Errno 30]

I’m trying to build a snap with Electron and a Python server running in the background. When building the Python code via Python plugin I’m facing below error.

+ snapcraftctl build
+ python3 -m venv /root/parts/server/install
+ SNAPCRAFT_PYTHON_VENV_INTERP_PATH=/root/parts/server/install/bin/python3
+ pip install -U pip setuptools wheel
Collecting pip
  Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Collecting setuptools
  Using cached setuptools-58.3.0-py3-none-any.whl (946 kB)
Collecting wheel
  Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, setuptools, wheel
  Attempting uninstall: pip
    Found existing installation: pip 20.0.2
    Uninstalling pip-20.0.2:
ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '__init__.py'

Failed to build 'server'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

After some trial and error I’ve found that the root cause is this section of my snapcraft.yaml file.

extensions:
  - gnome-3-38

When I comment it out, my snap builds fine but so far I haven’t managed to find a solution to the problem and the error message didn’t help a lot.

I’ve built a minimal reproduction here -> https://github.com/nemwiz/snapcraft-python-gnome-issue

The extensions do a lot of their work by manipulating your YAML before it gets built, you can view the changes the extensions make to your yaml with the command snapcraft expand-extensions

The Gnome extensions set PYTHONPATH at build-time, and this may be causing the error, (though there might be other Python related variables there). I’d suggest trying to unset the $PYTHONPATH variable the extensions create.

You could try something like this

part-name:
  source: ...
  override-build: |
    unset PYTHONPATH
    snapcraftctl build

You might also be able to just make use of the build-environment functionality too, assuming the extensions don’t overwrite it still.

part-name:
  source: ...
  build-environment:
    PYTHONPATH: "invalid"

The reason I use the word invalid rather than just “” is because I think snapcraft complains about empty variables, meanwhile I’d hope Python itself would just ignore the variable if it’s clearly defective.

2 Likes

Some additional info in this post (I ran into the same problem): Gnome extension conflicts with python plugin