A
A
anton_zaboev2022-01-06 19:56:52
PyCharm
anton_zaboev, 2022-01-06 19:56:52

How to solve encoding problem in pycharm?

Suddenly this error appeared

SyntaxError: Non-UTF-8 code starting with '\xf3' in file C:\PROJECTS\KURSOVAI\utils.py on line 25, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details.

words = ['улика', 'улика1']

if 'улика' in words:
    print(1)

example code. Until a certain point, everything worked fine. Googled on the Internet: renamed the project folder to English, renamed the computer name. Helped.
When I run the project from the main file I get the following error
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xf3 in position 0: invalid continuation byte

Please tell me what is wrong and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Eremin, 2022-01-06
@Sergei_Erjemin

This is not a problem with PyCharm, but with Python... Most likely Python 2.7
Write at the beginning of the python script:
# coding=utf-8
Or format UNICOD strings like this:
words = [u'улика', u'улика1']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question