Python 3 and Turkish Character In Debian - python-3.x

I have to do a project with turkish content. In my ubuntu machine with python 3.6.5, I haven't any problem with this. But in production server, that is a debian machine with the same python 3.6.2, I have:
SyntaxError: Non-UTF-8 code starting with ....
When I use # -*- coding: utf-8 -*- as docs, I have:
utf-8 can't decode byte
I have searched google and stackoverflow all day. And try all suggestions.
Any advice about this issue would be appreciated.

Related

Pygrib UnicodeEncodeError

I use python 3.9.1 on macOS Big Sur with an M1 chip.
I would like to open the grib format file which is provided by Japan Meteorological Agency.
So, I tried to use the pygrib library as below:
import pygrib
gpv_file = pygrib.open("Z__C_RJTD_20171205000000_GSM_GPV_Rjp_Lsurf_FD0000-0312_grib2.bin")
But I got the error like this:
----> 1 gpv_file = pygrib.open("Z__C_RJTD_20171205000000_GSM_GPV_Rjp_Lsurf_FD0000-0312_grib2.bin")
pygrib/_pygrib.pyx in pygrib._pygrib.open.__cinit__()
pygrib/_pygrib.pyx in pygrib._pygrib._strencode()
UnicodeEncodeError: 'ascii' codec can't encode characters in position 50-51: ordinal not in range(128)
I asked other people to run the same code, and it somehow worked.
I am not sure what the problem is and how to fix it.

fixing Module Not found Error when importing openpyxl in .py file?

I am trying to use openpyxl with python 3.7, but when starting my .py file in my windows shell I got the ModuleNotFoundError.
It is kinda weird as i don't get this error if I write my code in the python interpreter (can create and save .xlsx files)
I tried uninstalling and installing again via pip3 and/or running shell as admin (pip is updated).
I don't use many other modules (os, wx, csv and calendar) so it shouldn't interfere.
I renamed my .py file so i'm sure there is no name conflict.
import openpyxl
#from openpyxl import Workbook (doesn't work either)
Do you have an idea where this may coming from ?
regards,
Clem
I think I found a solution, as I don't get the error anymore.
I added the encoding and language interpreter at the beginning of my .py file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from openpyxl import Workbook
Hope it helps :)

Reading data in Spyder with a different encoding

I'm trying to read a .spydata file into Spyder, which was written in a different platform (and probably with a different encoding), but spyder gives an error :
'ascii' codec can't decode byte 0xb5 in position 2: ordinal not in range(128)
I tried changing my encoding setting before loading spyder without success. Any ideas?
I fixed the encoding problem with this line on top of the file:
# -*- coding: utf-8 -*-
https://python.readthedocs.io/en/stable/howto/unicode.html
You can change de encoding if you need too. But I don't know if you can include the encoding line on the file you mentioned. Hope It helps.

Tkinter Import Error on Puppy Linux

I'm having a few problems running tkinter on my Puppy Linux laptop using Geany to write and execute the code. I've got Python 3.1 running ok, but whenever I try to
import tkinter
I get the following error message:
file "/usr/lib/python3.1/tkinter/__init__.py", line 40, in <module>
import _tkinter
UnicodeEncodeError: 'latin-1 codec can't encode characters in position 0-3: ordinal not in range(256)
I don't have the foggiest what's going on!
I changed the Geany filetypes.python document from:
compiler=python -m py_compile "%f"
run_cmd=python "5f"
which runs Python2 as the default (tkinter imports fine with this!), to:
compiler=python3.1 -c "import py_compile;py_compile.compile('%f')"
run_cmd=python3.1 "%f"
in order to allow me to use python 3.1 as the default. I did copy this code, rather than writing it as I'm not familiar with Linux.
I would like to know how I can successfully use tkinter with Python3 on PuppyLinux. I'm not tied in to using Geany, so any help is appreciated!
Rich

Python IDLE right-to-left language support

I have recently started to use python 3.4 on Ubuntu and installed python 3.4 IDLE.
I have used the IDLE before on Windows and it works fine and correctly displays Farsi or Arabic which are written right-to-left.
However, on Ubuntu when I try to print a Farsi word on python IDLE it does not show the word correctly.
Here is an example, the correct rendering of word is:
مجلس
but on IDLE I see
س ل ج م
Is this something related to Ubuntu or IDLE and how can I fix it?
# -*- coding: utf8 -*-
print(u"مجلس")
You need to add a header for utf8 on top to add support for those characters.

Resources