Debugging pyjamas python code - python

I am using pyjamas to develop a web page. I write python code which is translated to javascript by pyjamas. This way debugging programming error is caught only when testing the web page. It would be much more efficient if we can run the code first in the Python interpreter before compiling to javascript. This seems would require pyjamas-desktop be installed. I tried installing pyjamas-desktop but it was not straight forward for me and I could not succeed in installing pyjamas-desktop.
I am wondering if there is anyway to run the code to just check for errors i.e. I do not want to see the widgets popped up. But just running in the interpreter so that errors like missing to import a module that is used in the program are caught.

Pylint is probably the first place to start - it can be installed with easy_install then run as
$ pylint my_python.py
The verbosity of errors can be easily edited - but any major problems will be highlighted immediately - and you don't need those extra pyjamas-desktop modules installed! Other similar tools (that do the same sort of thing) are PyCheckMate (syntax check only), PyChecker, and PyFlakes.

Related

How does a good python debugging workflow look like?

My latest python debugging workflow appears extremely slow to me, and little satifying. How can I improve?
Setting: I work with some third-party python packages from github.
Workflow:
run into error after entering some command to the terminal (Ubuntu WSL, python 3.7)
read terminal error message output, most likely the first or last one is helpful
from the last message i take the code reference (ctrl+left mouse in vscode) and look at the code
i find some function call in the third party module that looks very unrelated to the problem
i add import pdb to the module, and a pdb.set_trace() before that function call
i run the program again, and it stops at the breakpoint
using n,r,u,d i try to navigate closer to the source of the error
i eventually find some error raise condition in some other module, where some property of a certain variable is checked. the variable itself is defined some levels up in the stack
re-running the program and stopping at the same breakpoint as before, i try to navigate to the point where the variable is set. I don't know on which level of the stack it is set, so i miss it sometimes. I set intermediate breakpoints to save me some work when re-running
i finally find the actual cause of the error. I can check out the workspace and eventually fix the error.
i go through all the modules and remove the import pdb and the pdb.set_trace
Thanks for any suggestions
are you using an IDE, not fully clear in your question?
they tend to have graphic ways of setting breakpoints and stepping,
and it saves the hassle of changing the source.
not going into ide opinions, but examples of ide's with debuggers are spyder, thonny and others.
you can also run the debugger via commandline to avoid changing source, but I don't think that's the way to go if you are looking to simplify the cognotive load.
Yes these things you have to do and in extra you can do include logging everywhere as applicable to get exact point where it got occurred.

Detect all missing imports in PyCharm/Python

Is there a simple way, preferably in PyCharm (2017.1) but via command-line python (3.5) if necessary, to detect all code places where a statement is referring to an unresolved reference, e.g. because an import statement is missing?
I am new to Python/PyCharm. More generally, any syntax errors or anything in a similar vein would be a bonus. All I am looking for is the kind of errors I would get if I were "compiling" and "linking" in another language.
I have looked at Can PyCharm list all of Python errors in a project? and PyCharm's "Inspect Code". It is way more complex than I had in mind (and takes ages to run). I see that Python Rope: How to Find all missing imports and errors in all sub modules refactoring recommends pylint, but I wasn't looking for lint-like. I just want darn-obvious errors!
I am tasked with porting a fair-size (32K lines) application, which (apparently) runs under Windows, to Linux. The first thing I want to do is get rid of some of the imports all over the place. If my application executes a line which then has an unresolved reference I get a runtime error, but I want to pick them all up at edit-time. And there will be paths of code which are Windows-only, but I still want to know of any errors like this.
To answer my own question:
From Can PyCharm list all of Python errors in a project?, you can indeed use Code|Inspect Code to get all these errors/warnings in PyCharm as a list where you can click to get to the code. It does take a long time, but at least it's built into PyCharm, and the errors reported correspond to what you see in the editor window.
Pycharm will list all errors and 'warnings' for each source file at the right-hand side of the editor window.
They are represented as short lines or small blocks, depending on the size of the error or 'warning'. Errors are shown in red.
You click on them to take you to the place of the problem in the source.
Warnings are mostly Python style-guide violations (PEP 8).
Another option is to use pylint. This is lint for Python. This will detect missing imports.
You can integrate it into PyCharm by following the instructions in https://stackoverflow.com/a/46409649/4459346

Python3/MacOSX integration into pycharm

I have had trouble setting up the pycharm ide on my macosx10.7 with python3..
I have scoured every resource available and tried hundreds of approaches, at this point I must accept my incompetence and seek help via this channel.
In my research, I notice a lack of ground-up explanations on python integration into macosx and how to configure pycharm to import modules, run code within the editor, etc. If i ever solve this I will make a very detailed tutorial.
I have imported python3 successfully, it looks like it is linked appropriately from /sys/lib/frameworks to /usr/lib ...etc -- version control is working just fine.
I think my issue is either in setting environmental variables (tried the program to fix this and tried macports) and in the script needed to execute. it will catch errors throughout but final product does not run in python and returns printout of :
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 /Users/anon/Desktop/pythonpractice/Py_Ex/classes.py
Process finished with exit code 0
i really need to get this configuration sound for my python programming class. please help (I've been through every line of pycharm website) .. preferably is there a way to map it via terminal? thanks for anyone who took the time to read this.
Summary of the discussion above:
Python 3.2.2 installation was broken on this Mac, installing ActiveState Python 3.2.2 from scratch and configuring it in PyCharm has fixed the problem.
Python path to be used in PyCharm settings: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
Incompatible third-party plug-ins may break PyCharm, uninstall/disable them in Preferences | Plugins.
Ensure the latest PyCharm version is installed.
User's code depends on the graphics.py module which was not in the project or in the PYTHONPATH. Putting it into the project has solved the problem.
Most likely the wrong Run/Debug configuration was used in PyCharm, the easiest way to run or debug such scripts is by using the editor context menu Run and Debug actions. PyCharm creates the configuration automatically and debugging works fine as shown of the screenshot:
If one wants to configure and debug it, he can use the code.zip file to get started.
Sorry for the comments mess above, but it was not possible to move it into chat as user had only 1 reputation point, hence not able to use the chat feature of StackOverflow.

compiling python code from gedit

I am using WinXP.
I am using gedit (2.30.1) as python IDE. But I don't how to compile my code from inside the gedit. I've searched the net, but can't found any good solution.
First of all, you don't compile a python code. Python's code is interpreted.
EDIT:
gedit doesn't come by default with the plugins necessary to do the development. You will have to install them. Look in the comment for the link.
You can also checkout a blog link.
Using any simple text editor won't give you much flexibility in running the code right from the application. Unless you add a few plugins here and there to gEdit, you couldn't do it natively from Linux either.
If you're keen on sticking with gEdit for your needs, then you would have to install the plugins in your system - here is a link that may be of use to you. If you're fine with moving to another text editor, then I would strongly recommend Geany, which does the same thing as gEdit, but is more fully-featured, and can allow for execution of code in the same application.
You almost never need to compile Python code, although sometimes, as a optimization, Python code could be transfered into C code for a higher performance with certain plugins. Python code are translated to *.pyc and run in a PVM.

How to get started with a bare-bones Eclipse + PyDev

I am planning to move from SPE to Eclipse + PyDev for better code completion. I think SPE's code completion is rather weird.
Anyway, how should I get started with Eclipse + PyDev? I browsed http://www.eclipse.org and I found that Eclipse is made up of some base/core system and plugins are added for more functionality. I also stumbled upon http://www.easyeclipse.org which offers a ready-to-use Eclipse + PyDev distribution.
I have two options: the easy way and the hard way.
EASY WAY
Just download from http://www.easyeclipse.org. Problem is, I can't decide which version to use, v1.2.2.2 or v1.3.1?
HARD WAY
I want to keep a lean Eclipse installation, so I want to start out with a bare-bones download, then add plug-ins as I advance in skill. As of the moment, all I want in an IDE is the following:
Proper code completion, and
An easy shortcut key to run the current program. It should be something like F5 or F9.
Eventually, I will want to use more advanced tools, but I want to add plug-ins when I need or want to learn them:
Debugging
Unit testing
Version control
What plug-ins should I install to get the specific features I just mentioned?
The leanest Eclipse installation is the Platform Runtime Binary at around 50MB (look for it in the middle of the page). Install it and then once in eclipse go to Help->Install New Software... and use http://pydev.org/updates as link to install PyDev and you are done. Not very hard at all.
I've never really used the PyDev with Eclipse, but Eclipse comes with shortcut keys - you can change them to whatever suits you. If you install the standard version of Eclipse (which isn't exactly "lean", you know) with PyDev, you should have debugging built in. You can get Eclipse plugins for virtually any VCS you like, whether that's git or bazaar, subversion or CVS. Just check out the list.
edit: and it doesn't look like there's any reason not to use the newest stable version of Easyclipse, if that's what you decide.
I have used EasyEclipse for a while, but though less errors and incompatibilities occurred than in the standard version at that time, I didn't like that some modules were either too old or not supported at all. Meanwhile the standard distribution is stable enough.
Debugging and unit testing are integrated in PyDev. You must configure the Python interpreter in the preferences, "Auto config" should do, then choose "Run as..." "Python unit-test" on a Python module, and for debugging see the "Run" menu. Version control depends on what you use, I think CVS is already integrated, but I use Subversion, and for that you need to install the Subversive plugin (meanwhile available from the Eclipse repositories, but you must still install it).

Categories