Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'encodings' #481

Open
jangrewe opened this issue Nov 12, 2021 · 8 comments
Open

ModuleNotFoundError: No module named 'encodings' #481

jangrewe opened this issue Nov 12, 2021 · 8 comments

Comments

@jangrewe
Copy link

Description
Mariner can't be started on DietPi

Reproduction Steps
Steps to reproduce the behavior:

  1. Install DietPi on SD card, boot and do minimal setup to get a running system.
  2. Follow setup instructions to install mariner package from PPA
  3. (optional) Install dbus to make systemd behave properly

Expected Behavior
Mariner starts, preferably from the systemd unit, but manual start via sudo -u mariner mariner is acceptable.

Screenshots / Logs

dietpi@marsbox:~$ sudo -u mariner mariner
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0xb6fc6a00 (most recent call first):
Aborted

Details:

  • Mariner Version: 0.2.0-1
  • Printer Model: Elegoo Mars
  • Raspberry Pi Model: RPi Zero W

Additional context
Add any other context about the problem here.

@jangrewe
Copy link
Author

I guess this is the problem:

dietpi@marsbox:~$ ls -l /opt/venvs/mariner3d/lib/python3.7/encodings
lrwxrwxrwx 1 root root 28 Apr 17  2021 /opt/venvs/mariner3d/lib/python3.7/encodings -> /usr/lib/python3.7/encodings

But DietPi (based on Rasbian/Debian 11) has Python 3.9, so the correct target for the symlink would be /usr/lib/python3.9/encodings.
Trying the stupid thing and symlinking /usr/lib/python3.7 to /usr/lib/python3.9 helps with a couple of errors, but not enough to get it to work.
I think the big issue is that you're using a packaged venv that makes incorrect assumptions about the environment it gets installed to. Maybe it would be better do do a pip3 install . from sources, when the package gets installed? That would at least ensure the correct environment is used.

@dmpanch
Copy link

dmpanch commented Nov 14, 2021

@jangrewe

I fixed it by copying python 3.9 to the mariner directory, copying some files from python3.7 to python3.9 directory, and editing/relaunching the post-install script. It's faster than compiling required Python on Zero.

Symlink Python 3.7 to the Python 3.9

cd /opt/venvs/mariner3d/bin
sudo ln -s python3.7 /usr/bin/python3.9

Copy Python 3.9 libs to the mariner:
sudo cp -r /usr/lib/python3.9 /opt/venvs/mariner3d/lib/python3.9

Go to the mariner directory and copy some files/dirs from the Python 3.7 to the Python 3.9 directory:

cd /opt/venvs/mariner3d/lib/python3.7
sudo cp no-global-site-packages.txt ../python3.9/no-global-site-packages.txt
sudo cp orig-prefix.txt ../python3.9/orig-prefix.txt
sudo cp site.py ../python3.9/site.py
sudo cp -r site-packages/ ../python3.9/site-packages/

Edit postinstall script adding Python 3.9 version - find the next string and add Python 3.9 version:
sudo nano /var/lib/dpkg/info/mariner3d.postinst
local pythonX_Y=$(cd "$dh_venv_install_dir/lib" && ls -1d python3.9 | tail -n1)

Run postinstall script:
sudo /var/lib/dpkg/info/mariner3d.postinst configure

Now web interface is running but there are another error "Unexpected Printer Response" (I don't have a connected printer yet, so not sure if this error cannot be due to this fact)

Traceback (most recent call last):
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/mariner/server/api.py", line 46, in print_status
    selected_file = elegoo_mars.get_selected_file()
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/mariner/mars.py", line 102, in get_selected_file
    self._extract_response_with_regex("ok '([^']+)'\r\n", data).group(1)
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/mariner/mars.py", line 39, in _extract_response_with_regex
    raise UnexpectedPrinterResponse(data)
mariner.exceptions.UnexpectedPrinterResponse

@jangrewe
Copy link
Author

jangrewe commented Nov 14, 2021

Thanks @dmpanch, i've now rebuilt everything against Python 3.9 and got it to work, at least theoretically. Your approach is probably a lot faster, so i'll give that a shot for the next time.

But i guess it would be nicer if the package would be built for the current Python version, i guess.

Anyways, now i'm running into a problem similar to yours (which doesn't look like it's python related, though):
The printer returned an unexpected response: 'ok N:20\r\n'

Traceback (most recent call last):
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/venvs/mariner3d/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/opt/mariner/mariner/server/api.py", line 54, in print_status
    selected_file = retry(
  File "/opt/mariner/mariner/server/utils.py", line 54, in retry
    return func()
  File "/opt/mariner/mariner/printer.py", line 103, in get_selected_file
    self._extract_response_with_regex("ok '([^']+)'\r\n", data).group(1)
  File "/opt/mariner/mariner/printer.py", line 40, in _extract_response_with_regex
    raise UnexpectedPrinterResponse(data)
mariner.exceptions.UnexpectedPrinterResponse: ok N:20

That looks like mariner doesn't understand what printer's status output?
edit: okay, found this: #180

@dmpanch
Copy link

dmpanch commented Nov 17, 2021

@jangrewe totally agree with you about the Python version. Btw, today I found PPA with the different Python versions, it would have been useful a few days ago.

@Moba160
Copy link

Moba160 commented Jan 2, 2022

Thank you dmpanch, you saved my day.

There is only one slight mistake in your ln command, the parameters need to be swapped; the correct command is
sudo ln -s /usr/bin/python3.9 python3.7

@antwal
Copy link

antwal commented Jan 7, 2022

Problem solved, check here #493 for install python 3.7.4

@hiddentapir
Copy link

I got around this by starting with a legacy raspbian image. The Debian Buster based image released Dec 2nd 2021 comes with python 3.7 instead of 3.9, and Mariner installs & runs with no issues.

@kane-thornwyrd
Copy link

kane-thornwyrd commented Feb 20, 2022

‼️#481 (comment) is harmful because you are basically mixing two versions of python hoping for the best, maybe it worked, fine, but you may have screwed the installation of any other softwares relying on Python 3.9 you may want to install later.

I'm in the process of writing a comprehensive issue with a sane solution included, maybe using pyenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants