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

[Windows] Python + UTF-8 Encoding? #214

Closed
Braintelligence opened this issue Oct 20, 2014 · 18 comments · Fixed by #2421
Closed

[Windows] Python + UTF-8 Encoding? #214

Braintelligence opened this issue Oct 20, 2014 · 18 comments · Fixed by #2421

Comments

@Braintelligence
Copy link

Hi there,

when executing Python3 code with

print(" STRING ")

Where STRING contains letters like öüä, there's a problem with the encoding. It shows as . (While the console in windows command prompt shows it correctly.)

If I use #coding=latin-1 it works but this shouldn't be necessary!

Sorry if I missed this issue within the others.
Please help me out =(

@rgbkrk
Copy link
Member

rgbkrk commented Oct 20, 2014

Hmm, seems like it's interaction with Windows that isn't doing well. For me on a Mac, using python3 it works perfectly:

screen shot 2014-10-20 at 4 02 55 pm

@rgbkrk rgbkrk changed the title Python + UTF-8 Encoding? [Windows] Python + UTF-8 Encoding? Oct 20, 2014
@Braintelligence
Copy link
Author

I heard that Windows is using UTF-16 encoding in its console. Maybe that's the reason for this issue?

Edit

I'm using Windows 8.1 64-bit. I installed ATOM via Chocolatey and am using the packages atom-beautify, color picker, minimap and atom-keymap-compatible (unofficial package for resolving this issue: atom/atom-keymap#35 )
For Themes I use Seti UI and Seti Syntax. The code I'm compiling is Python3 (Python also installed via chocolatey) and the console output is only correct if I choose latin-1 as python encoding-environment-setting while the windows console has a correct output if the python executable is called from there.

image

@Braintelligence
Copy link
Author

Still have this problem with Atom 0.141.0 and Script 2.13.0
Encoding shows up fine in Atom (thx to the new feature, heh). Correct symbols are still shown in windows command line when executing python

Did you try enforcing a UTF-8 encoding before it hits the "script-console"?

@erran
Copy link
Collaborator

erran commented Dec 25, 2014

As mentioned by @poliorcetics this is an issue in Mac OS X too. We could both produce it under Yosemite.

Adding the following comment to a Python file:

# é

Causes this issue for either of us:

  File "/Users/ecarey/github/atom-script/examples/i18n.py", line 1
SyntaxError: Non-ASCII character '\xc3' in file /Users/ecarey/github/atom-script/examples/i18n.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

As noted in the PEP-0263 reference adding the annotation will fix the issue. This is the suggested fix, but for easy use the below changes could fix this within the Script package.

  • Prepend # coding: UTF-8 where UTF-8 is substituted with whatever encoding is selected by Atom (bottom left).
    • Through a configuration option.
    • Automatically similar to how we prepend whitespace to ensure the correct error line is reported.

@erran
Copy link
Collaborator

erran commented May 2, 2015

@Braintelligence can you confirm whether adding the special coding comment resolves this issue for you? I believe it resolved #252.

@erran erran added the needsinfo label May 2, 2015
@Braintelligence
Copy link
Author

I'm very sorry but I am not using Atom editor anymore since this issue is going on for over a year now: atom/atom-keymap#35

For me this editor is not being maintained properly till proven otherwise.

@dbolton
Copy link

dbolton commented Dec 31, 2015

@erran Adding the utf-8 comment to the top of the file doesn't stop it from showing the question marks for me. Python 3.5.1, Atom 1.3.2, Windows 10.

@dbolton
Copy link

dbolton commented Jan 19, 2016

@erran and @Braintelligence I was able to find a workaround to the problem.

For me, it looks like atom-script on Windows uses cp1252 (Windows 1252) encoding by default instead of utf-8 (the default encoding may depend on your locale and platform).

As a work-around you can specify the encoding as utf-8 in your code for the system out and error streams:

import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

print ('öüä')

@Braintelligence
Copy link
Author

@dbolton Thanks, but I really moved on and am now very happy with PyCharm. :)

@J-qak
Copy link

J-qak commented Apr 7, 2016

I haven't looked at script source codes, but shouldn't this have easy solution? Isn't it possible to just change encoding for console view on Windows?

@sinedanat
Copy link

After 2 years this problem still exists.
I use this plugin for runnning haskell code on Winwdos 7.
Maybe the simplest solution is to add another option for encoding in settings?

@rgbkrk
Copy link
Member

rgbkrk commented Oct 31, 2016

If you've got a fix, please submit a pull request.

@silvium
Copy link

silvium commented Jun 11, 2017

@sinedanat after 3 years. And counting. VS Code is starting to look more and more inviting.

@rgbkrk
Copy link
Member

rgbkrk commented Jun 11, 2017

I highly recommend using Hydrogen over this module for running your code. I don't have time to work on this one.

@alexjosesilva
Copy link

Estou executando este codigo

  • *- coding: utf-8 - *-
    import os, sys

print "EXPEDIÇÃO DE DESPACHO"

e esta saindo:

EXPEDIÇÃO DE DESPACHO

@rgbkrk
Copy link
Member

rgbkrk commented Sep 4, 2018

Almost 4 years!

@mambari
Copy link

mambari commented Sep 5, 2018

solution found on internet : create a environment variable

PYTHONIOENCODING=utf-8

@github-actions
Copy link

🎉 This issue has been resolved in version 3.31.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

9 participants