Python Forum
keep getting 'encoding' error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
keep getting 'encoding' error
#1
Have installed NetBeans and then the Python plugin but whatever I try to code (even a one-line like print("hello world") I always get the following error. "SyntaxError: Non-ASCII character in file 'D:\test\src\test.py', but no encoding declared; see http://www.python.org/peps/pep-0263.html for details"

Am on Windows 10

I'd like to post a screenshot here but when I click the above symbol for Image, it asks for an image URL. What is that? Does my image have to be accessible online? If so where? Normally you get a prompt to browse to a location on my PC
thanks
Reply
#2
well, did you check the PEP?
you need to declare the encoding used in your py file, e.g. at the top of the file put this line
# coding=utf-8
or

# -*- coding: utf-8 -*-
These are examples for utf-8 encoding. use whatever your encoding is...
Reply
#3
Dos not need to declare encoding in .py if use Python 3(as he should).
Python 3.6 and pip installation under Windows
Reply
#4
Thanks to you both for responding

my two lines of code now looks like this:

# coding=utf-8
print("Hello World")
yet get exactly same error!

Also, can I get an answer to this question which I asked previously? many thanks

I'd like to post a screenshot here but when I click the above symbol for Image, it asks for an image URL. What is that? Does my image have to be accessible online? If so where? Normally you get a prompt to browse to a location on my PC
Reply
#5
1) What version of Python are you using?
2) Try writing your script using Notepad. Run the file from the command terminal. If it runs correctly in the command terminal, the problem lies in the Netbeans configuration.

(Feb-16-2018, 04:21 PM)harry1948 Wrote: Thanks to you both for responding

Also, can I get an answer to this question which I asked previously? many thanks

I'd like to post a screenshot here but when I click the above symbol for Image, it asks for an image URL. What is that? Does my image have to be accessible online? If so where? Normally you get a prompt to browse to a location on my PC

What question are you referring to that wasn't addressed. Also, do not post screen images. Copy and paste the error code in it's entirety between the error tags.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
Do you use Python 3.6 as i posted link to?
# coding=utf-8 is not needed in Python 3 as it's use utf-8 as default encoding.
Here a example:
hello.py saved in folder C:\foo\hello.py
print("Hello World")
Start cmd:
Microsoft Windows [Version 10.0.16299.248]
(c) 2017 Microsoft Corporation. Med enerett.

C:\WINDOWS\system32>cd\

# Test python version
C:\>python -V
Python 3.6.4

# Test pip
C:\>pip -V
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)

# Run with path to file
C:\>python C:/foo/hello.py
Hello World

# Navigate to foo folder and run
C:\>cd foo
C:\foo>python hello.py
Hello World

C:\foo>
If this doesn't work try saving hello.py with and other editor.
To make sure that that editor you use don't mess up with byte order mark (BOM).
Reply
#7
snippset, sorry I missed seeing your link to 3.6 install. I have now done that install. When I dble-click python.exe I get a cmd window and python starts and gives me a >>> prompt and print("hi") returns hi ok so python seems to be installed. But I dont see my PATH variable has been set so any idea what it should point to? I did a default install to C: sparkz_alot you refer to a command terminal but that isn't my >>> prompt is it? Also why do you say not to post images? surely it's easier for everyone to do so as is done on most forums? Is it completely forbidden here?
Reply
#8
(Feb-18-2018, 03:38 PM)harry1948 Wrote: When I dble-click python.exe I get a cmd window and python starts and gives me a >>> prompt and print("hi") returns hi ok so python seems to be installed. But I dont see my PATH variable has been set so any idea what it should point to?
You have to start cmd(Command Prompt).
Here you type python and Python should start,also pip -V to check pip.
Quote: Is it completely forbidden here?
No,but we usually prefer code in code tag,i am gone post a picture of cmd(command prompt),
because i don't even think you know what it is.
[Image: 6Vxl61.jpg]
cmd(command prompt) is an important part here you do all install with pip.
So if you followed my link about install 3.6 it should works as in image.
Here tutorial about cmd(Command Prompt).
Reply
#9
I have now followed your install pages on a new laptop and it has all worked exactly as your screenshots show (well done for providing those, it made it very clear). The last thing I did was install the requests package and I ran the various commands which, I assume, are to prove everything is installed correctly. So it's all working fine. So, I have Python but I need an IDE to write my programs and I think Netbeans looks like what I need. So do I now go ahead and install it or perhaps should I have done that already? Thanks for your help.
Reply
#10
You are doing it in exactly the correct order. Most if not all IDE's require Python to be pre-installed. They in turn look at the environmental variables to determine the main Python directory (and thus the python.exe, Python builtins, installed packages, etc.)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error notification after encoding robertje1024 1 1,194 May-29-2022, 04:18 PM
Last Post: Axel_Erfurt
  Encoding Error Racer_x 7 2,589 Nov-05-2021, 07:27 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020