Sublime Text 3 and Python 3 - exception messages - python-3.x

I've just switched to Sublime Text 3 (from ST 2 actually) and I am getting this annoying error message when executing an invalid code. Say, I run this code (which is of course invalid in Python 3):
print 'this'
I am getting this extended error message from my Sublime:
SyntaxError: invalid syntax
[Finished in 0.2s with exit code 1]
[shell_cmd: python -u "C:\Users\Myname\Desktop\working.py"]
[dir: C:\Users\Myname\Desktop]....CUT HERE...
So alongside the exception Sublime is printing all the environment variable paths that I have. I am guessing this is abnormal behavior? or do you get this kind of error messages as well on Sublime Text 3?
If this is of any relevance, I have both Python27 and Python 33 installed, although only Python33 is put into variable paths.

Install the Better Build System package. Add these settings to your user preferences (Preferences -> Settings - User):
"show_panel_on_failed_build_only": false,
"show_debug_text": false,
"show_panel_on_build": true

Took me too long to notice you aren't talking about Sublime's plug-in interface (that uses an embedded copy of Python 3), but about the "Build" command that just runs the file in the Python interpreter found in the PATH.
To answer your question- yes, I get this kind of messages whenever I run some code in Python that exits with non-0 exit code. Could just be:
import sys
sys.exit(1)
Change this to exit(0) and the output is just:
[Finished in 0.0s]
So looks just it's just Sublime's build tool trying to be helpful.

According this documentation, https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function you need to include parenthesis like this print ('this')

Related

Pylint cannot detect the missing space after # sign of comments and missing blank line, Python3

I have written a try_pylint.py file to try if pylint can detect some incorrect style with Python 3.10.
"""This is a try for pylint detection.
"""
#hello world! --> missing a space, and it has only 1 (needs 2) blank line before it.
def print_hello():
"""print it
"""
print('hello')
If I run the command in terminal pylint try_pylint.py, it gives
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
However, if I use flake8, it can detect both of them.
flake8 try_pylint.py gives
try_pylint.py:4:1: E265 block comment should start with '# '
try_pylint.py:6:1: E302 expected 2 blank lines, found 1
Could you please show me how to configure pylint to detect them? By the way, I am using VS Code for developing Python code. It would be great if you can show me how to configure it on VS Code.
Thanks in advance!
The actual check is done by pycodestyle inside flake8. pylint do not check for this and for formatting in general (as black can format your code automatically, this kind of check are not very useful anymore).
You should use black, flake8 and pylint together, they are not mutually exclusive.
Just a note about comments handling in Pylint: there is a pylint checker that shows messages for empty comments in your code. The message/checker is called empty-comment.

SyntaxError: Non-UTF-8 code starting with '\x90' in file .\score_python.exe on line 1, but no encoding declared;

I have a python script where I need to create an executable via pyinstaller. Successfully created the exe, but shows the above error while running.
I have already searched on the web and tried many solutions but none of them is working. tried with # -*- coding:utf-8 -*- in the first line of the script but fails.
using Python3.7, PyInstaller3.5
Can anyone help me with this?
Ensure you are not calling the executable using python again.
As in
python long-path-to-the-converted-scrip\script.exe
It is a common mistake, due to the fact that you used python to run the script before, then you try to recycle the same command but forget to delete the python call. The long path to the script (now converted to exe) obfuscates the fact that python is no longer needed at the beginning...hence your error.
Resolution: Please execute the exe without python command.
Example: If you have converted test.py, please go to the directory Current Directory/dist/test/ and either double-click on test.exe or run test.exe from command line.

os.popen doesn't work after compiler with pyinstaller

The following line is what I'm using to open the file in python, and this action called by a button(tkinter).
os.popen(r'"C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe" %s' %filename)
My development environment is Python3.7 + spyder 3.3.1 + windows 7 + latest version pyinstaller.
The issue is that this line can work well in spyder, but after compiler.
pyinstaller -F -w --onefile --icon=icon.ico ./DMS.py
I used this command to compile the Python script. When I click the button which I mentioned above, there is no any action be executed and no any error message pop up. I'm sure the application didn't hang on or crush.
When I try the following command to check what message on console.
pyinstaller -F DMS.py
The miracle happen, the PDF file can be opened without problem, and there is no any error message show on the console.
Does anyone know what things happen? and any suggestion for this case if show the console front of end user is not an option.
Many thanks.

Not able to run Red language script on Linux

I am trying to run following simple script file:
#! /usr/local/bin/red-063
Red []
print "testing"
quit
But I am getting following error:
** Script Error: Invalid compressed data - problem: -3
** Near: script: decapsulate
if none? script
This error is mentioned on this page: https://github.com/red/red/blob/master/environment/system.red but details are not clear and also how it can be corrected.
Similar script for Rebol 2.7.8 works. Where is the problem?
The problem is with rebol not being able to unpack. See here.
Essentially create a batch file or shell script in the directory as the red binary to invoke the red binary.

PyCharm: IDE does not seem to recognise Python 3 even with 3.x interpreter set

I am using the latest version of Pycharm(pycharm-2017.1) and have used Pycharm for a couple of years without issue. However, I have never written Python 3 scripts with it before, and have issues now. I am getting red underlined syntax errors which appear to clearly indicate that Pycharm doesn't understand that I'm using Python 3.
In 'Edit configurations', I have set Python 3.x to be the default interpreter... I'm not sure what I'm doing wrong.
Note: I have the correct python3 shebang lines in my scripts, and running them both straight from a terminal, or even by pressing 'run' in Pycharm works no problem.. this latter fact just adds to the mystery.
I also tried adding (with the '+' in 'Edit configurations', specific profiles for each of the scripts concerned, with Python3.x as the interpreters, to no avail)
Thanks for reading
The Edit configurations settings refers to the running options only.
To use python3 at project level you need to change the interpreter in File > Settings > Project: project-name > Project Interpreter
This allow to have correct syntax-checking, import-checking and others

Resources