Syntax Error on print('hello', end='')
arturhoo opened this issue · 6 comments
Hi there,
The valid python3 syntax below:
print('hello', end='')
generates a E901 SyntaxError: invalid syntax
. I believe this could be somehow related to #66. Cheers
PS.: I'm on Sublime 3 on OS X, plugin version 2.3.2
Hi! Which Python interpreter do you use? Could you, please, turn on "debug" mode in plugin settings and provide me debug output?
I'm using python 3.4.3. Here is the debug log:
[Flake8Lint DEBUG] run lint by 'on_post_save' hook
[Flake8Lint DEBUG] run flake8 lint
[Flake8Lint DEBUG] ignore file patterns: []
[Flake8Lint DEBUG] python interpreter: auto
[Flake8Lint DEBUG] interpreter is external
[Flake8Lint DEBUG] guess interpreter: 'python'
[Flake8Lint DEBUG] linter file: /Users/artur/Library/Application Support/Sublime Text 3/Packages/Python Flake8 Lint/lint.py
[Flake8Lint DEBUG] interpreter is external
[Flake8Lint DEBUG] lint time: 0.207ms
[Flake8Lint DEBUG] lint errors found: 1
[Flake8Lint DEBUG] 'select' setting: []
[Flake8Lint DEBUG] 'ignore' setting: []
[Flake8Lint DEBUG] 'is_highlight' setting: True
[Flake8Lint DEBUG] 'is_popup' setting: True
[Flake8Lint DEBUG] prepare flake8 lint errors
[Flake8Lint DEBUG] error to show: (48, 19, 'E901 SyntaxError: invalid syntax')
[Flake8Lint DEBUG] show flake8 lint errors
[Flake8Lint DEBUG] highlight errors in view (regions: error)
[Flake8Lint DEBUG] show popup window with errors
[Flake8Lint DEBUG] close errors popup window
@arturhoo I think plugin could use python 2.x (this is default python in OS X). This strings tells plugin used default OS X python:
[Flake8Lint DEBUG] guess interpreter: 'python'
[Flake8Lint DEBUG] interpreter is external
Could, you, please, show me an output of python -V
command? This is mine:
➜ python -V
Python 2.7.6
I should add this info to debug output later.
I didn't quite understand what you meant. My python version is 3.4.3
~ $ python -V [2.2.1]
Python 3.4.3
I should emphasise that the syntax I mentioned above is only valid in Python3:
~ $ python [2.2.1]
Python 3.4.3 (default, Mar 11 2015, 15:24:35)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
hello>>>
~ $ python [2.2.1]
Python 2.7.9 (default, Mar 11 2015, 15:24:06)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
File "<stdin>", line 1
print('hello', end='')
^
SyntaxError: invalid syntax
I should emphasise that the syntax I mentioned above is only valid in Python3
Yes, that's that I'm talking about :) Flake8Lint plugin takes system python and use it to lint your code. I am sure it takes Python 2.x, not python 3.x, because OS X use Python 2.x by default, and that is why I asks you to provide me an output of python -V
command (in clean terminal console, without any virtualenv's or whatever), because Flake8Lint use exactly this command: python
to run linter.
Ok, let's go another way. Could you, please, set correct full path to your Python 3 interpreter in your project config? Here is the link to documentation about project options: https://github.com/dreadatour/Flake8Lint#project-flake8-config
Or you could setup python interpreter for all your projects in plugin config (option python_interpreter
): https://github.com/dreadatour/Flake8Lint#plugin-config
I am sure problem will disappear then you will setup correct python interpreter, because right now plugin uses Python 2.x to lint your Python 3.x code.
The reason geany is showing syntax error for print("hello",end="") cause by default it uses python 2.7 and in python 2.7 (end=" ") is not available so to solve this issue you have to change python 2.7 to python 3 manually to do that follow given step:
- In geany select build option from the toolbar
- After that when it shows many options select set Build command
3)Then after a new window will pop up then from python command on compile change python -m py_compile "%f" to python3 -m py_compile "%f"
4)Then from execute command change python "%f" to python3 "%f"
problem solved.
you can also use python3.latest_version (3.7) to use all latest features of python.
I hope this will help you.