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

UnicodeDecodeError from setup.py with python3.6 and LANG=C #84

Open
ktns opened this issue Feb 5, 2020 · 3 comments · May be fixed by #85
Open

UnicodeDecodeError from setup.py with python3.6 and LANG=C #84

ktns opened this issue Feb 5, 2020 · 3 comments · May be fixed by #85
Assignees
Labels

Comments

@ktns
Copy link

ktns commented Feb 5, 2020

Hi,

I've encountered an error while installing your package in a docker image.
It boils down like below.

%docker run --rm python:3.6 env LANG=C pip install --no-binary :all: uModBus==1.0.3
Collecting uModBus==1.0.3
  Downloading uModbus-1.0.3.tar.gz (19 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7mj5qq3n/uModBus/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7mj5qq3n/uModBus/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-7mj5qq3n/uModBus/pip-egg-info
         cwd: /tmp/pip-install-7mj5qq3n/uModBus/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-7mj5qq3n/uModBus/setup.py", line 12, in <module>
        long_description = open(os.path.join(cwd, 'README.rst'), 'r').read()
      File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 547: ordinal not in range(128)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I think I can prepare a PR to fix this.

@ktns ktns linked a pull request Feb 5, 2020 that will close this issue
@OrangeTux
Copy link
Collaborator

Thanks for opening this issue. It seem a duplicate of #60 . I was wondering, could you share the Dockerfile you used? I'd like to reproduce the problem myself.

@jaapz
Copy link
Member

jaapz commented Feb 8, 2020

@OrangeTux i can reproduce this by running the command in the original issue.

$ docker run --rm python:3.6 env LANG=C pip install --no-binary :all: uModBus==1.0.3
Collecting uModBus==1.0.3
  Downloading https://files.pythonhosted.org/packages/eb/1c/852af30263b6fd44e160951d35f70f26a4c7b1f15458c174402c04d0753b/uModbus-1.0.3.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-qagdmmru/uModBus/setup.py", line 12, in <module>
        long_description = open(os.path.join(cwd, 'README.rst'), 'r').read()
      File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 547: ordinal not in range(128)
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-qagdmmru/uModBus/
WARNING: You are using pip version 19.1.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

When you remove the env LANG=C part from the command the build works.

A quick google gives me this: https://stackoverflow.com/questions/39206705/python-3-throws-unicodeencodeerror-with-environment-variable-lang-c

tldr: setting LANG=C tells python to use ASCII as default encoding. However the README.rst contains unicode characters, so it breaks.

I think setting encoding="utf-8" in the open call should fix this:

long_description = open(os.path.join(cwd, 'README.rst'), 'r', encoding="utf-8").read()

I haven't tested this though.

@jaapz
Copy link
Member

jaapz commented Feb 8, 2020

Ah I see that's also what you proposed in the PR 🙃

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

Successfully merging a pull request may close this issue.

3 participants