I know about the Django console and it's useful to an extent but it would be really nice to be able to edit your code with the console open, lime SLIME in Emacs. Is there anything that facilitates this for Django or, failing that, at least Python?
I do not know if this is exactly what you are looking for, but Workzeug provides a interactive debugging tool, which can be used like that. Just do a assert False and you can use the CLI as demonstrated in this screencast: http://ericholscher.com/blog/2008/sep/12/screencast-django-command-extensions/
IDLE
Running
django-admin.py shell
in your project should give you what you want. If you have IPython installed, you also get all of the fancy highlighting and completion features it offers too.
Related
I am currently debugging code using Python. I have not been using Python for a while. I put some breakpoints on a variable which is an integer. Let's say this variable is X = 10. How can I:
see what is in the variable? (I can highlight and a yellow case appears but if there are a lot of information it is not practical to display like this)
do some manipulation of the variable, for example I would like to do X+2 and get the result?
As noted in the comments, there are many possible IDEs you can use with Python. The original question was specifically about Eclipse and so my answer focuses on a solution using that IDE. Other solutions are possible if you prefer a different environment...
First off, you need to sort out which plug-in you use for eclipse. You have a few options as you can see on the python wiki. It looks like PyDev is more popular, but you could pick others.
Assuming you go for PyDev, you can use the watch facility as described here to evaluate any expression. Alternatively you can use the console debugger to evaluate code directly in the debugger.
EDIT: As per the comments, you can also open the Expressions window using Window > Show View > Other > Debug > Expressions. This is the same window as used for the watch facility and the contents can be edited directly.
I'm sure everyone has their own opinion, but I find the python tools for Eclipse quite complex. If you aren't tied to an Eclipse IDE, try PyCharm. It has very good tools for doing exactly what you want, and many tutorial videos. This video shows you how to do exactly what you have requested: https://www.youtube.com/watch?v=QJtWxm12Eo0
I don't think you can do this purely in Eclipse, not without extensive plugins. However, there are some very good python debugging tools out there.
If you're willing to get your hands dirty, the builtin python debugger pdb does everything you want and more. Import pdb, pdb.set_trace() where you want to break, and you step into an interactive debugger that's very familiar if you've used gdb before.
If you want to use something more IDE focused, I recommend Immunity Debugger. It's really rather good, and has a lot of documentation. This might be a little more than you're looking for though.
Try opensource, free VS Code (with Python plugin). It has a slick intellisense feature and you can watch, inspect the variables, debug them. The editor is node.js based and can work in every platform. Eclipse is overkill for python development IMHO.
ipdb is a handy tool for python debugging:
ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better introspection with the same interface as the pdb module.
To install ipdb, simply run pip install ipdb --user in your shell.
To set breakpoint, add import ipdb; ipdb.set_trace() before the line where you want to jump into the debugger. E.g.:
import ipdb; ipdb.set_trace()
X=10
Once you run your program python myfunc.py, an IPython-like interactive shell will be triggered and you can run python commands in it. E.g.:
ipdb> p X
10
ipdb> X+2
12
Here is a simple tutorial: An Introduction to Python Debugging
Are there any IDEs for Python that support automatic error highlighting (like the Eclipse IDE for Java?) I think it would be a useful feature for a Python IDE, since it would make it easier to find syntax errors. Even if such an editor did not exist, it still might be possible to implement this by automatically running the Python script every few seconds, and then parsing the console output for error messages.
eclipse+pydev
pycharm
many others ....
If you use VIM or don't have a problem with it, try this extension. https://github.com/klen/python-mode
This is for Emacs as well: https://github.com/gabrielelanaro/emacs-for-python
Also pycharm and eclipse with pydev work fine.
If I don't use vim I really enjoy spyder. It is easy to use and has some really nice features, like integrated debugging and profiling, graphical variable explorer and object inspector. The latter shows, e.g., the integrated documentation for every function of class you use.
I built an extension to Eclipse and PyDev that does what you describe, it runs the Python code as you're typing, and displays all the variable values and any exceptions that occur. It's called Live Coding in Python, and the web site has a tutorial and a demo video.
PyDev can highlight some problems in your code by analysing it, and Live Coding in Python can show you problems that happen when you run it.
I recently installed IPython after hearing about it on this forum. I am looking for an environment that is similar to what might come with MATLAB or RStudio for R.
I was under the impression that IPython would give me that but the version I downloaded for Windows looks very bare. In fact I do not really see a difference between IDLE and IPython except tab completion and history (which I have been wanting) but this is about as much as the interpreter that comes with R which I used to think was hard to work with.
Have I misunderstood the point of IPython? Or is it possible that I have not installed correctly?
I have also downloaded the 'Console' and while I am not convinced that it is working properly, it looks very bare as well.
Komodo looks good but is somewhat costly. Netbeans and Eclipse also look good, but do not seem to be straightforward to install, at least for somebody with my level of knowledge, so it would be good if somebody could verify their compatibility with Python, features, and ease of use for a non-expert user.
I suggest you try Spyder
You can find it here : https://www.spyder-ide.org/
It is perfect for you : it is a lightweight Scientific IDE with the explicit purpose of being similar in feel to matlab.
It has an editor, a console and lots of neat features and plug-ins.
It can use IPython as its console.
IPython is "just" an enhanced python console with pure awesomeness built-in. (actually it's much more : it's a client-server architecture with multiple interfaces to pure magic, in console mode, Qt, and even inside a browser with the Notebook)
Definitely check it out later on when you've used the basic console for a while.
For the context, i've been using Eclipse, pycharm, got tired of those, and i started to ask around what people use, and the one i've heard the most about is sublime text.
You should take a look, maybe it's what you are looking for!
I just saw it's not open source though!
What i'm using now is Ninja-IDE, which is written in python and is open source and seems pretty good! It has plenty of plugins, which includes an IPython plugin
Have you tried the qtconsole backend? It was released after you asked your question.
This is a very lightweight widget that largely feels like a terminal,
but provides a number of enhancements only possible in a GUI, such as
inline figures, proper multiline editing with syntax highlighting,
graphical calltips, and much more.
From the Windows command prompt, enter:
ipython qtconsole
In PHP, it was extremely easy to start hacking away and figuring out what was going on on a page. Just throw in a bunch of echos and print_r's and that was about it. It appears that this technique is not working for me in python. I am getting practice by hacking around in a python photo upload module, and when a photo is uploaded, it creates 3 different size photos. I found the code that does this, but I want to see the state at that particular moment. I tried doing a "print" on the size variable, but it did not show up in my browser.
I guess a more straightforward question would be, is it "pythonic" do debug using the browser ( equivalent to echo's and print_r's in php ), or is this what the python console is for? Thanks!
Use the logging module rather than printing stuff to stdout.
Using the interpreter in interactive mode is a great way to try out code, and pdb is very useful for real debugging.
It's "pythonic" to do debugging using the pdb module.
But really, if you're just "hacking around", then I suggest messing around with an interactive interpreter interface, especially one that supports autocompletion (Python itself comes with IDLE right out of the box).
You need to learn how to use a debugger ;) Hacking with prints is cool for simple php, but you can save a lot of time in higher languages with a debugger.
As mentioned, PDP is a place to start http://docs.python.org/library/pdb.html
As others have mentioned PDB, I'll take the opportunity to sing the praises of Eclipse using the pydev plugin, which is absolutely fantastic. IDLE is also well worth a go. Both of these IDEs allow you to step through code, inspect variables, auto-complete, etc. etc.
http://pydev.org/
Download Eclipse then use the Software Updates menu to add in PyDev.
http://pydev.org/updates
PyCharm from JetBrains is as good as all their other products. It has an integrated debugger and lots more.
I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started.
Under Unix, Emacs is a good choice, to which I always come back, because it is convenient to have a single editor for everything, and because it's open source.
What is best for you depends on your past experience with IDEs. I'd say: stick with what you've been using, or take this opportunity to try an even better IDE.
Note: Python comes with Idle, which is a very simple (if limited) IDE.
Be sure to check out IPython. It's an enhanced interactive python shell with a bunch of useful features such as Tab-Completion using introspection (eg, type "my_object." to see a list of its attributes and methods), logging your interactive session to an executable python-file, defining macros, etc. The documentation page has a link to the tutorial as well as screencasts showing it in action.
On my mac/Linux machines, python came pre-installed. On windows I use both jython under the eclipse IDE and ActivePython with their IDE/eclipse. With eclipse you'll want PyDev.
It all depends on what you are looking for and what you are already using.
For instance, if you are using a more 'simple' editor at the moment: as long as it's got Python syntax you've got the basics.
If you are used to e.g. Eclipse you can just continue to use that, combined with Pydev. Besides syntax highlighting you'll also get more fancy features to help you debug and refactor your code.
Personally I use Emacs with python-mode (and a few other modes to interface with Subversion and Git). In the past I used Vim which also worked quite well.
My advice would be to start out with your current environment as long as it has some rudimentary support for Python. Once you are familiar with the language, start exploring what your environment is missing and either add it or if you cannot, switch to an enviroment which does support the feature.
I use gvim with some plugin in order to have better support for python.
If you like IDE, look at wing IDE wich is the best I have tested so far. Especially the debuger included is really helpful.
The Python Beginner's Guide and the official Python Tutorial both seem like good places to start.
Geany is a good option for a Linux setup, it's intellisense isn't that great but syntax highlighting is good and it can compile your code directly from inside the editor, plus it handles other languages such as C/C++, PHP, Java etc... Eric is another popular choice as it's a full IDE and I know some people use Eclipse.
On windows I use Notepad++, but it's mostly because I like text editors instead of fully blown IDE's.
Reference wise Daniel's choices are very good places to start, also check out Green Tea Press who do free computer books, there are two Python choices on there but the "Python for Software Design" book hasn't yet been published properly although you can download the manuscript. The "How to Think Like a Computer Scientist" book is a good one and not as scary as it sounds.
IDLE is nice to try out things. Other tools that people like are Eclipse with the Pydev plugin which seems to work ok, although it has crashed a few times (Eclipse, that is) and NetBeans (which I haven't tried) but some people seem to like.
I can only help you if you're running a Mac. Download Xcode. I believe that Python 2.3 comes bundled with these development tools. Luckily enough, this is all you really need to get started, unless you want a newer version of Python.
All you need to do is open up Terminal and type python. You're done!