7

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:

  1. 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.
  2. 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.
  3. The path to executable does't contains special characters.

Tests done:

  1. Remove exe extension from pserve. Didn't worked: not recognized command message.
  2. Call pserve-script.py instead pserve (full path tried too). Didn't worked: do nothing and returns nothing.
  3. Added "-*- encoding: utf-8" at the start of pserve-script.py. Same message.
  4. 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.

Diogo Paschoal
  • 1,507
  • 1
  • 14
  • 16
  • 1
    You forgot to ask a question. – IInspectable Dec 07 '16 at 23:20
  • 1
    Please include exact code or command line you are using to run pserve. This looks like Python is trying to run the .exe as if it was a Python script. – RichVel Dec 09 '16 at 05:49
  • @RichVel, Added in the question. – Diogo Paschoal Dec 12 '16 at 22:25
  • Refer [Old Post] (http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-in-python-source) that should help you – MarmiK Jan 02 '17 at 10:18
  • 1
    http://stackoverflow.com/a/41435691/13986 I've answered the same question in that SO question. Pyramid 1.8 should work much better, please give it a shot. – X-Istence Jan 03 '17 at 02:51
  • @X-Istence, the problem is that we have to pin the versions. What worked to me whas really uninstall and install again (I was dumb to not try this at the first). – Diogo Paschoal Jul 17 '17 at 11:55

3 Answers3

0

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:

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.

Community
  • 1
  • 1
RichVel
  • 7,030
  • 6
  • 32
  • 48
  • I already use bash for windows, but i want to integrate pycharm or vscode with the virtualenv (python utility) on Windows. i'm using WSL too to execute my scripts, but there is no clean way to do the integration with WSL (remote linking is not clean. i've searched about). Used VMs in the past too, but is not what i'm searching for. Besides this pserve should REALLY work without problems with the virtualenv. – Diogo Paschoal Dec 19 '16 at 14:22
  • Assuming 'pserve' is really a Python script, try `python pserve development.ini --reload` - if this works, put it in a `run-pserve.bat` file. To check if your virtualenv setup is correct you can also use `/path/to/my/venv/bin/python pserve development.ini --reload` which forces use of the virtualenv even if env vars etc are not right. – RichVel Dec 19 '16 at 15:34
  • I've tried full path too, @RichVel. Edited the question to reflect this. Also, pserve-script.py is just a wrapper to call pserve.exe. Tried both absolute and relative call to both files (exe and py). – Diogo Paschoal Dec 19 '16 at 17:08
0

Assuming your virtualenv sits in venv directory

Use this:

python venv/Lib/site-packages/pyramid/scripts/pserve.py some-ini-config.ini --reload
julx
  • 8,694
  • 6
  • 47
  • 86
0

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.

Sovello
  • 9
  • 1
  • Agree with you about the suggestion to interpreter encoding, but this do not apply for the pyramid bundle, because we'd have to rewrite the package on each installation. Reinstall it is more simple, easier to replicate and less error prone. Change the interpreter encoding is very useful in the files you're editing, not as solution to third-party libs. – Diogo Paschoal Oct 04 '19 at 18:37