How to get PyCharm to display unicode data in its console? - python

I have switched over to PyCharm and have had a blast using it. I code for projects that use languages other than English (i.e. Hebrew and Arabic) and need to debug encodings once in a while. For some reason, PyCharm will not display Unicode characters in its debug console.
I have set the IDE encoding to UTF-8 but it did not help.
Any ideas?

The accepted answer is no longer correct. Of the default fonts, none of them make a difference. I just spent awhile going through this same problem and the best solution is to modify your .bash_profile (or .zshrc) and include the line:
export PYTHONIOENCODING=UTF-8
In theory, you could also add this to your Environment Variables which you can set from within Preferences->Build,Execution,Deployment->Python Console
This approach, however, seems to be broken in the build I am using (4.0.4)

You need to change the console font to the one which contains the required Unicode glyphs:

Related

How do I fix Unicode Display Issue in Windows 7 with either FontTools Font-Merging or Manually Editing a System File?

Update: This issue is now solved. It actually appears that the issue is that the Unicode characters are somehow not being recognized by Uniscribe at all, and so no fallback font is used at all. The only feasible system-wide solution without trying to repair or change Uniscribe appears to be to change the name of Segoe UI Symbol to Arial (this can be done by converting the file to .ttx XML format and manually editing the file, then converting back to .ttf), and use this new "Arial" font as the base font which other Unicode fonts can be merged into with FontTools. I discuss what I've learned about merge / pyftmerge in more detail here.
The issue I'm trying to solve is the exact same issue/question asked here many years ago:
https://superuser.com/questions/784078/some-unicode-fonts-not-working-in-windows-7-firefox
If you read through the question/responses, you'll see that no actual conclusion was reached and no actual answer was found as to why some Windows 7 systems fail to display characters in uncommon Unicode blocks like Egyptian Hieroglyphics even though the relevant fonts are installed.
Furthermore, no general solution was found either (the OP concluded with a "solution" specifically for Firefox). The OP mentions that he has very extensively tried a large number of potential solutions to no avail.
My intuition is that this issue has nothing to do with graphics cards. I believe this is entirely a Windows issue and specifically a Uniscribe issue.
I suspect that the discrepancy between the OP testing the issue on his VM (where the unicode characters display properly) and on his local machine (where the unicode characters do not display), is possibly due to his local machine and his VM having different versions of usp10.dll. However, as the question is 6 years old and the OP does not appear to be active, there is no way to ask to confirm this hypothesis.
Upon inspecting usp10.dll with a hex editor, there are actually a decent amount of intelligible ASCII sections:
My actual question is what "should" I do to solve this issue? And furthermore, if someone has a decent idea of how to actually execute one of the solutions that I'll propose below, please explain the nitty-gritty. (I don't consider "upgrade to Windows 10" a valid answer. Although I understand that there are many good reasons to do so, please do not post a reply if this is your only suggestion.)
From what I've gathered, I can see 3 solutions to this issue:
I can go out of my way to get a VM and a fresh installation of Windows 7 to test my hypothesis relating to usp10.dll. If my hypothesis was true, I can possibly transfer the "good" version of usp10.dll to my local machine. The downside is that I do actually have to go out of my way to do this, as I don't own a VM and I no longer have my Windows 7 installation disc.
I can experiment with manually editing usp10.dll locally and see if this produces any helpful results. For instance, there may be some parts of the code where I can append additional font names such as Symbola and Aegyptus. If I'm very lucky, this may fix the issue by allowing Windows to fallback to these fonts. The obvious downside is that I don't understand Uniscribe or Windows DLLs near enough to be "qualified" to do this. Furthermore, I would have to do this for every additional "obscure" unicode font that I install in the future.
Lastly, perhaps the easiest solution I can think of, is to use the same approach EmojiOneColor and TwitterColorEmoji uses for their Windows installation procedure. Which is to merge additional fonts (in my case, Symbola and Aegyptus) into Segoe UI Symbol, and I believe this should almost guarantee that these additional Unicode characters are displayed properly, since Segoe UI Symbol is used by Windows by default.
The obvious advantage to the last approach is that it's relatively easy to do and almost guaranteed to work. And if defined to not replace any existing glyphs, would also give the same appearance as Windows using the correct fallback font. Furthermore, it can be automated with a script that you can run every time you want to merge a new font into Segoe UI Symbol. I currently don't have such a script, but maybe someone here can help me with that (TwitterColorEmoji uses Python FontTools). The downside to this approach is that I believe font files have a max number of glyphs, so there might be a limit to how many fonts I can stack up inside of Segoe UI Symbol.

Can I force character encoding inside a python script? [duplicate]

This question already has an answer here:
Task output encoding in VSCode
(1 answer)
Closed 2 years ago.
I'm having a problem with characters not rendering properly.
Background: I am taking online courses to learn Python. I use VSCode as my IDE along with various python extensions.
Problem: Some of the lessons I solve have characters that are beyond the 128 standard ASCII set.
Sample: For clarity, this is the full script I'm dealing with. The currently lesson has text containing a small e with acute (é) in a painting named Vétheuil in the Fog. Unfortunately that acute-e character is rendered as a placeholder (�) and ends up outputting: V�theuil in the Fog.
Efforts: I have done some searching and thought I found a solution: including an encoding flag at the beginning of the python script like this:
# coding=UTF-8
No joy.
Am I tilting at a windmill / misunderstanding purpose or application?
Money Question: Is there a way to get the character to properly render when I run the script?
If you want Unicode characters to be displayed correctly, you'll need to use a terminal, that supports Unicode or change the terminal settings to work with Unicode, in case the terminal provides that option.
Of course the same way you can make the terminal able to display only extended ascii characters like "é" (as long as you have a terminal that provides this functionality), in case you don't need more characters.
This has been sufficiently addressed.
VSCode Panel displays different things via tabs below the editor region. The OUTPUT tab has the displayed different and therefore becomes a question of my setup; not error as the TERMINAL tab displays characters as expected. So, there is no problem to be solved beyond my misunderstand of what was happening.
As #user2357112supportsMonica also provided "An encoding comment declares what encoding your script itself is written in," not how the output is rendered.
Thank you all for helping me through this.
Just to cap this topic. A PERFECT solution to this is provided here:
https://discuss.codecademy.com/t/general-nerdiness-questions/541682/7?u=coreblaster01537

Changing Eric6 appearance configuration

I'm trying to use Eric6 python IDE and have been struggling with making it fit my needs better. I want to use it as a poor man's Matlab, thus many advanced features are useless to me, plus some programming habits are actively hindered by Eric.
can I disable "variable unused" warnings? I've been searching through settings over and over again to no avail. The problem is those warnings "inject" themselves into the code as extra lines which is a real sore for the eyes.
alternatively, it could be a floating text that doesn't shift everything below by one line.
Prevent it from switching to Log-Viewer every time I run a script. I just want to use the shell like in Matlab for quick access to variables.
Does anyone have experience with this IDE?
1) The only (GUI-availeble) option here seems to be to disable the code checkers part all together.
[ Settings > Preferences > Editor > Code Checkers > Automatic syntax check ]
-- Reload the file to get rid of any lingering code-checker messages.
-- Checked against Eric6 (18.06)

What's the closest thing to SLIME for python ? / What's the best way to use python from EMACS?

I'm trying to write some python, and I'm used to the lispy way of doing things, a REPL in EMACS and the ability to send arbitrary code snippets to the REPL. I like this way of developing code, and python's built-in IDLE seems to do it pretty well. However I do like EMACS as an editor.
What's the best thing analogous to SLIME for Python?
So far:
It seems that the trick is to open a python file, and then to use 'Start Interpreter' from the Python menu, after which you get an Inferior Python buffer. You can then use C-c C-c to load the whole buffer you're editing into the 'REPL', and use normal copy and paste to put snippets into the REPL.
This works as far as it goes. Is there any way to say 'reevaluate the big thing that the cursor is in now and display the answer', or 'reevaluate the thing the cursor is just at the end of and display the answer', like M-C-x and C-x-e in SLIME?
And it all seems to work better if you use the python-mode.el from Bozhidar's answer
There is ipython.el which you can use for some extended functionality over the vanilla python-mode. Ropemacs provides a few extra completion and refactoring related options that might help you. This is discussed here. However, I don't expect you're going to get anything close to SLIME.
I think the new python.el is a much better idea. It's under active development, it can spawn a python shell and send function definitions, buffers and files to it. It also has better than average re-indent support. It's rumoured that in Emacs 24 it might become the default python mode in Emacs.
python-mode is the default mode for editing Python in emacs. It includes commands for evaluating the buffer and running an inferior interpreter instance.

Lightweight console/IDE for Python?

I often use ipython (or the regular python shell) to test python code snippets while coding, and it's been very useful. One shortcoming of this, though, is that if I want to test a multi-line segment of code, or want to write multiple lines of code before running, it isn't very convenient to have to do it "line by line". And even going back to change some of the lines is cumbersome because you have to re-type all the code that comes after it.
I'm playing with Groovy right now and I find that it has an excellent solution to this problem: the Groovy Console. You just write all the code you want, it's just like a regular editor; and then you hit run Ctrl+R (Cmd+R actually since I'm on a Mac) and it runs everything at once. If you want to change something (e.g. if there are errors), then that's easy too -- just change it and Ctrl+R again.
Is there an equivalent of this available for python? Or do you have any recommendations on a way to achieve similar behavior? I could just create a new file, save it, and then python <filename>.py from the shell. But that's just too many steps and would be cumbersome. Eclipse may be an option, but it's too heavyweight. I'm really looking for something lightweight that I can just spin up when I want to test something and then get rid of it just as quickly.
I'd be interested to hear any ideas/suggestions!
Thanks
You might give DreamPie a try. As far as I can tell from a quick read of the groovyConsole page you linked to, DreamPie features a similar input area/output area division (they call it "code box" and "history box"). The code you execute is by default cleared from the code box - which groovyConsole apparently doesn't do - but you can easily retrieve it (Ctrl+Up), or change a preference setting to "Leave code in the code box after execution".
Have you tried using IDLE, the standard Python IDE? You'd have to save the code as <filename>.py within IDLE, but after that you can run it using F5.
The Python docs link to this intro to IDLE, which may be helpful even if it's a little outdated.
I am using emacs and its python-mode.
C-c C-c: evals the current buffer
but you can also eval region (ie selection), functions etc ...
You can even make python-mode use ipython (like I do).
See http://ipython.scipy.org/dist/ipython.el . It works nicely
Did you try PyCrust? It has excellent multi-line editing, copy/paste support.
PyCrust can be found in wxPython Docs and Demos.

Categories