非 ASCII 字符 '\x90' 在 vi​​rtualenv 中的 Windows 上执行 pserve [英] Non-ASCII character '\x90' executing pserve on windows inside virtualenv

查看:29
本文介绍了非 ASCII 字符 '\x90' 在 vi​​rtualenv 中的 Windows 上执行 pserve的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:如何解决在 windows 中的 virtualenv 上执行 pserve 时出现无 ASCII 字符错误?

Question: How can i solve no-ascii character error executing pserve on virtualenv in windows?

描述:我正在尝试在 Windows 上的 virtualenv 中执行 pserve(pyllons/pyramid 开发网络服务器).这是全新安装,所以可能与版本有关.

Description: I'm trying to execute pserve (pyllons/pyramid development web server) inside a virtualenv on windows. It's a fresh install, so maybe it is related to versions.

问题: 激活 virtualenv 后,执行 pserve config.ini 抛出错误:SyntaxError: Non-ASCII character '\x90' in file C:\PATH_TO_MY_ENV_HOME\env\Scripts\pserve.exe 在第 1 行,但没有声明编码;详情请参见 http://python.org/dev/peps/pep-0263/.

Problem: With the virtualenv activated, execute pserve config.ini throw error: SyntaxError: Non-ASCII character '\x90' in file C:\PATH_TO_MY_ENV_HOME\env\Scripts\pserve.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details.

命令行:

pserve development.ini --reload

注意事项:

  1. 当您的文件包含与当前文件编码不匹配的字符时会发生此错误,因此您可以添加一条指令以在 Python 脚本开始时设置正确的编码.
  2. 如果在某些情况下被调用的目标具有 exe 扩展名,并且调用它的脚本在末尾添加一个 exe,则可能会发生这种情况.因此,python 运行时会抛出此错误,因为 exe 文件不能作为脚本调用,而只是在不添加后缀的情况下调用.
  3. 可执行文件的路径不包含特殊字符.

已完成的测试:

  1. 从 pserve 中删除 exe 扩展.无效:无法识别命令消息.
  2. 调用 pserve-script.py 而不是 pserve(也尝试了完整路径).没有用:什么都不做,什么都不返回.
  3. 在 pserve-script.py 的开头添加了-*- encoding: utf-8".同样的消息.
  4. 从 python.exe 中删除 exe 扩展(也尝试了完整路径).无效:无法创建进程".

环境:

  • Windows 10 1607 内部版本 14393.447
  • Python 版本:Anaconda2、Python 2.7.11
  • 金字塔版本:金字塔 1.7.3
  • 虚拟环境:15.1.0

解决方案:

卸载并重新安装解决了我的问题.

Uninstall and install again solved the problem to me.

推荐答案

此错误消息带有建议,内容为

This error message comes with a suggestion and it reads

语法错误:/path/to/file 文件中的非 ASCII 字符\x90"位于 #lineno 行,但未声明编码;参见http://python.org/dev/peps/pep-0263/ 详情

SyntaxError: Non-ASCII character '\x90' in file /path/to/file on line #lineno, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

粗体部分是建议所在的位置.此 PEP 非常简单,解决方案只是为您的源文件定义编码.你很可能有

The bold part is where the suggestion is. This PEP is very straight forward and the solution is just to define an encoding for your source file. You will most likely to have

#!/usr/bin/env python
# coding=utf-8

解释器行是可选的,但如果有解释器行,则可以在第二个定义编码,如果没有,则可以先定义

The interpreter line is optional, but the coding can be defined second if you have interpreter line or first if you dont

根据您的字符集设置编码.utf-8 应该适用于大多数情况,或者您可能需要其他编码.

Set the encoding depending on your character sets. utf-8 should work for most cases, or you may need other encodings.

这篇关于非 ASCII 字符 '\x90' 在 vi​​rtualenv 中的 Windows 上执行 pserve的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆