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

Fix encoding issue when installing with Pip3 #58

Closed
wants to merge 1 commit into from

Conversation

Zowie
Copy link

@Zowie Zowie commented Jun 22, 2015

When installing with pip3, the following error is given:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 48: ordinal not in range(128)

It appears that if you don't explicitly set the encoding with locale.setlocale(locale.LC_ALL, 'en_US.utf-8') --- or whatever locale, just the encoding matters AFAIK --- python will try to decode files using ascii (the locale.getpreferredencoding(False) function that open() actually depends on for the type of encoding it uses returns ANSI_X3.4-1968). This generates an issue where Python will say it cannot decode using ascii and the installation will fail.

I'm manually setting the encoding depending on the Python version now, i just copied line 48 (in old setup.py) to check the python version.

@bung87
Copy link

bung87 commented Aug 10, 2015

fixed my problem

gregmuellegger added a commit that referenced this pull request Aug 31, 2015
Similiar, but slightly different approach to what @Zowie suggested in #58.
@gregmuellegger
Copy link
Owner

@Zowie I adopted your fix, but wrote it myself to encapsulate it into it's own function. See this commit: a87c359

Can you confirm that this fixes the issue you are having?

@Zowie
Copy link
Author

Zowie commented Sep 2, 2015

@gregmuellegger Jup, fixes it as well!

@gregmuellegger
Copy link
Owner

Released 0.5.1 which contains this fix. So installing should be easier now on Python 3.
https://pypi.python.org/pypi/django-mobile/

@tysonclugg
Copy link

I know this is a bit late, but io.open() behaves consistently across both Python 2 and 3. It returns unicode strings when the mode set to 'rt' (the default), or byte strings when mode is 'rb'. Just use io.open('path/to/file', encoding='utf-8').read() and you'll get Unicode strings with both Python 2 and 3.

@gregmuellegger
Copy link
Owner

@tysonclugg nevertheless its good input! Thanks, I will use io.open in the future for these cases.

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

Successfully merging this pull request may close these issues.

4 participants