---
title: "python No-ASCII character ,编码错误"
author: "vergilwang"
date: "2013-01-09T10:39:00Z"
tags: []
categories: ["编程语言"]
slug: "python-no-ascii-character"
draft: false
lastmod: "2014-02-15T15:45:01Z"
id: 2011287
url: "https://vergilwang.iteye.com/blog/2011287"
---

# [python出现Non-ASCII character '\\xe7' in file ex6.py on line 1, but no encoding declare错误](http://www.cnblogs.com/windowswind/archive/2012/02/15/2450090.html)

 

python中出现Non-ASCII character '\\xe7' in file ex6.py on line 1, but no encoding declare的错误

![](http://pic002.cnblogs.com/images/2012/144456/2012020623242740.png)

可按照错误建议网址查看http://www.python.org/peps/pep-0263.html

发现是因为Python在默认状态下不支持源文件中的编码所致。解决方案有如下三种：

一、在文件头部添加如下注释码：

\# coding=&lt;encoding name&gt; 例如，可添加# coding=utf-8

二、在文件头部添加如下两行注释码：

#!/usr/bin/python

\# -\*- coding: &lt;encoding name&gt; -\*- 例如，可添加# -\*- coding: utf-8 -\*-

三、在文件头部添加如下两行注释码：

#!/usr/bin/python

\# vim: set fileencoding=&lt;encoding name&gt; : 例如，可添加# vim: set fileencoding=utf-8 :