Printing Unicode in eclipse Pydev console and in Idle - python

My configuration: Win7 + Python 2.6 + eclipse + PyDev
How do I enable Unicode print statements in:
PyDev console in eclipse
Idle Python GUI
Example print statement:
print(u"שלום עולם")
This comes out as:
ùìåí òåìí

For eclipse unicode console support:
Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
In eclipse - Run\Run Configurations\Python Run\configuration\Common\ make sure UTF-8 is selected
In eclipse - Window\Preferences\General\Workspace\Text file encoding\ making sure UTF-8 is selected
In [python install path]\Lib\site.py - change from encoding = "ascii" to encoding = "utf-8"
Make sure you're using unicode supporting fonts in eclipse - Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit
In the installation I did all of the above:
print(u"שלום עולם") # Doesn't work
print("שלום עולם") # Works
For django models:
print(my_model.my_field) # Doesn't work
print(my_model.my_field.encode('utf-8')) # Works

I was having the a same problem in Eclipse Luna 4.0.4 with Python 3.4.1 and PyDev 3.6.0. I tried the steps given above, and a few others, and was getting nowhere.
What worked for me was, in Eclipse, in Preferences —> PyDev —> Interpreters —> Python Interpreter, in the Environment tab, I added the environment variable PYTHONIOENCODING and specified its value as utf-8.
That did the trick for me…

PYTHONIOENCODING is a pretty good generic way of fixing this problem. However, the Eclipse way of setting the locale of its console is as follows:
Set the Run Configuration encoding:
Edit Run Configuration
Click on "Common" tab
Set Encoding to "UTF-8"

Related

SyntaxError: Non-UTF-8 code starting with '\xc4'

Problem while importing module
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import win32com.client
when I run it in eclipse, syntaxError occurs.
but it runs perfectly on Windows console.
how to type the right coding of pywin32?
For eclipse unicode console support:
Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
In eclipse – Run\Run Configurations\Python Run\configuration\Common\make sure UTF-8 is selected
In eclipse – Window\Preferences\General\Workspace\Text file encoding\making sure UTF-8 is selected
In [python install path]\Lib\site.py – chane from encoding = “ascii” to encoding = “utf-8”
Make sure you’re using unicode supporting fonts in eclipse – Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit

Python unicode console support under Windows

I am trying to make an environment which allows printing of unicode characters both in Python 2.7 and 3.4, under Windows.
By using Cmder / ConEmu as a terminal, UTF-8 is fully supported out of the box.
However, Python support isn't so simple.
Python 3.3+
If I set chcp 65001, Python 3.3+ detects it and runs fine.
Python 2.7
If I set chcp 65001 it simply doesn't work at all. Python produces an error line while IPython doesn't work at all.
Apparently, by specifying set PYTHONIOENCODING=utf-8 both Python and IPython work and allows printing of some unicode characters.
For example I can do:
print u'\xc1'
but I cannot do
print u'\xc1\xc1'
which produces: IOError: [Errno 0] Error
Still, it's better than nothing, at least most Python 2.7 programs would run unmodified.
My question is that if I add
#chcp 65001 > nul
#set PYTHONIOENCODING=utf-8
to the end of cmder/vendor/init.bat, would that have any side-effects on Python 3.3+?
Also, is there any way to let unmodified Python scripts print u'\xc1\xc1' under Windows?

How to display unicode string in its natural language in PyDev console [duplicate]

My configuration: Win7 + Python 2.6 + eclipse + PyDev
How do I enable Unicode print statements in:
PyDev console in eclipse
Idle Python GUI
Example print statement:
print(u"שלום עולם")
This comes out as:
ùìåí òåìí
For eclipse unicode console support:
Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
In eclipse - Run\Run Configurations\Python Run\configuration\Common\ make sure UTF-8 is selected
In eclipse - Window\Preferences\General\Workspace\Text file encoding\ making sure UTF-8 is selected
In [python install path]\Lib\site.py - change from encoding = "ascii" to encoding = "utf-8"
Make sure you're using unicode supporting fonts in eclipse - Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit
In the installation I did all of the above:
print(u"שלום עולם") # Doesn't work
print("שלום עולם") # Works
For django models:
print(my_model.my_field) # Doesn't work
print(my_model.my_field.encode('utf-8')) # Works
I was having the a same problem in Eclipse Luna 4.0.4 with Python 3.4.1 and PyDev 3.6.0. I tried the steps given above, and a few others, and was getting nowhere.
What worked for me was, in Eclipse, in Preferences —> PyDev —> Interpreters —> Python Interpreter, in the Environment tab, I added the environment variable PYTHONIOENCODING and specified its value as utf-8.
That did the trick for me…
PYTHONIOENCODING is a pretty good generic way of fixing this problem. However, the Eclipse way of setting the locale of its console is as follows:
Set the Run Configuration encoding:
Edit Run Configuration
Click on "Common" tab
Set Encoding to "UTF-8"

Eclipse running 64-bit Python, rather than 32-bit

I am running OS X Lion, Python 2.7, and I am trying to setup Pygame to work with PyDev in Eclipse. I set up PyDev to use a custom-installed Python (not the default one). I forced this install to use 32-bit, which works fine in the Terminal - I can import Pygame, and other modules. However, when I use it in PyDev, it gives me a no matching architecture error. It also appears to be running in 64-bit mode.
The paths to the interpreter are the same.
import sys
print ("%x" % sys.maxsize, sys.maxsize > 2**32)
prints out ('7fffffff', False) while using Terminal, but in Eclipse/PyDev it prints out ('7fffffffffffffff', True)
The two paths (using sys.executable) are:
In Terminal it is:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
And in Eclipse it is
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
The path to the interpreter I used is: /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
I also tried manually specifying the interpreter in Terminal - Using the above path. It worked.
The default python that comes with the system is /usr/bin/python
I am using a 32-bit version of Eclipse classic as shown by an answer to this question.
Does anyone have any idea what is wrong?
You need to instruct eclipse to use 32-bit python.
Right-click on your project -> properties -> PyDen/Interpreter grammar and select "Click here to configure an interpreter not listed"
After you add your new python binary (e.g. C:\Python27\python.exe), you go back to the interpreter menu in the properties window and you select this interpreter from the corresponding drop-down menu.
I solved this by using a method describe in an answer to another question.
The answer said to go to your plugins/org.python.pydev/pysrc and open interpreterInfo.py. Then you replace all the instances of sys.executable with the path to the interpreter you want.
In my case, this meant changing them to /Library/Frameworks/Python.framework/Version/2.7/bin/python2.7
After that, open up eclipse and create a new interpreter with the same path, and it should work.

Eclipse / PyDev overrides #sys, cannot find Python 64bits interpreter

I'm working in a multiuser environment with the following setup:
Linux 64bits environment (users can login in to different servers).
Eclipse (IBM Eclipse RSA-RTE) 32bits. So Java VM, Eclipse and PyDev is 32bits.
Python 3 interpreter is only available for 64bits at this moment.
In the preferences for PyDev, I want to set the path to the Python interpreter like this:
/app/python/#sys/3.2.2/bin/python
In Eclipse/PyDev, #sys points to i386_linux26 even if the system actually is amd64_linux26. So if I do not explicitly write amd64_linux26 instead of #sys, PyDev will not be able to find the Python 3 interpreter which is only available for 64bits. The link works as expected outside Eclipse/PyDev, e.g. in the terminal.
Any ideas how to force Eclipse/PyDev to use the real value of #sys?
Thanks in advance!
I don't really think there's anything that can be done on the PyDev side... it seems #sys is resolved based on the kind of process you're running (not your system), so, if you use a 64 bit vm (I think) it should work...
Other than that, you may have to provide the actual path instead of using #sys...

Categories