问题
Question: How can i solve no-ascii character error executing pserve on virtualenv in windows?
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.
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
.
Command line:
pserve development.ini --reload
Notes:
- this error happen when you have a file with characters that doesn't match the current file encoding, so you can add a instruction to set the right enconde at the beging of the python script.
- it can happen if the called target have an exe extension in some cases and the script that call it add an exe to the end. So, python runtime throws this error cause an exe file must not be called as an script, but just called without sufix adding.
- The path to executable does't contains special characters.
Tests done:
- Remove exe extension from pserve. Didn't worked: not recognized command message.
- Call pserve-script.py instead pserve (full path tried too). Didn't worked: do nothing and returns nothing.
- Added "-*- encoding: utf-8" at the start of pserve-script.py. Same message.
- Remove exe extenstion from python.exe (full path tried too). Didn't worked: "failed to create process".
Environment:
- Windows 10 1607 build 14393.447
- Python version: Anaconda2, Python 2.7.11
- Pyramid version: pyramid 1.7.3
- Virtual env: 15.1.0
SOLUTION:
Uninstall and install again solved the problem to me.
回答1:
I don't really have an answer here as I don't use either Pyramid or Windows. However, this has been seen before by a few people and may be due to python.exe
being used to execute pserve.exe
, which won't work as that's an executable not a Python program.
Here are some links that might move this forward - recommend you join the Google Group as it has more concentrated Pyramid expertise:
Pyramid pserve.exe syntax error
Google Groups thread
Google search
One specific idea is to ensure you have a pserve.py
file not pserve.exe
and that you use python pserve.py
to run it. If the calling script has limitations, create a run-pserve.bat
batch file to call Python and test it outside the calling script.
Alternatively, you might want to use a pre-configured Linux VM on Windows. Or on Windows 10 there is a good 'Bash for Windows' aka Windows Subsystem for Linux that's really a full Ubuntu Linux. Either of these would make it much easy for development than Windows, I would think.
回答2:
Assuming your virtualenv
sits in venv
directory
Use this:
python venv/Lib/site-packages/pyramid/scripts/pserve.py some-ini-config.ini --reload
回答3:
This error message comes with a suggestion and it reads
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
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
Set the encoding depending on your character sets. utf-8 should work for most cases, or you may need other encodings.
来源:https://stackoverflow.com/questions/41029001/non-ascii-character-x90-executing-pserve-on-windows-inside-virtualenv