In RStudio, you can run parts of code in the code editing window, and the results appear in the console.
You can also do cool stuff like selecting whether you want everything up to the cursor to run, or everything after the cursor, or just the part that you selected, and so on. And there are hot keys for all that stuff.
It’s like a step above the interactive shell in Python — there you can use readline to go back to previous individual lines, but it doesn’t have any “concept” of what a function is, a section of code, etc.
Is there a tool like that for Python? Or, do you have some sort of similar workaround that you use, say, in vim?
IPython Notebooks are awesome. Here’s another, newer browser-based tool I’ve recently discovered: Rodeo. My impression is that it seems to better support an RStudio-like workflow.
Jupyter Notebook (previously known as IPython notebook) is a really cool project for interactive data manipulation in Python (and other languages, including R). It basically allows you to interactively code and document what you’re doing in one interface and later on save it as a:
notebook (.ipynb)
script (a .py file including only the source code)
static html (and therefore pdf as well)
You can even share your notebooks online with others using the nbviewer service, where people publish whole books. Furthermore, GitHub renders your .ipynb files. You can publish your Jupyter Notebooks as reproducible research articles on Authorea. For collaborative editing by multiple users, check out Google Colab built on top of Jupyter.
The default Jupyter Notebook version starts a web application locally (or you deploy it to a server) and you use it from your browser. As Ryan also mentioned in his answer, Rodeo is an interface more similar to RStudio built on top of the Jupyter kernel.
JupyterLab is a newer take on the UI allowing for more flexibility in how you edit your notebooks, control interactive widgets and even run commands in terminal emulators.
There’s also a Qt console for IPython, a similar project with inline plots, which is a desktop application.
Jupyter is a normal Python package and can be installed using pip install jupyter. To get all the scientific libraries running on your computer, however, it might be easier to try the official Jupyter Docker containers. For example, assuming your notebooks are in ~/code/jupyter, you can run the container as:
docker run -it --rm -p 8888:8888 -v ~/code/jupyter:/home/jovyan/work jupyter/datascience-notebook
If you are new to Python, you can install the free Anaconda distribution (http://continuum.io/downloads.html), which will install Spyder for you, as well as Python 2.7 and IPython. Spyder is very similar to RStudio.
JupyterLab aims to create a more desktop-like experience on the Web.
Update:
As of March 2018 JupyterLab is in beta. “The beta releases are suitable for general usage. For JupyterLab extension developers, the extension APIs will continue to evolve until the 1.0 release. Eventually, JupyterLab will replace the classic Jupyter Notebook after JupyterLab reaches 1.0.“
Pycharm is a really decent IDE. From what I have seen so far it is the most similar to Rstudio. Another nice piece is that it allows you to install new Python libraries in a fashion similar to Rstudio (which otherwise can be a nightmare). There is now a free ‘community’ edition.
spyder is you need!
https://code.google.com/p/spyderlib/
Spyder (previously known as Pydee) is a powerful interactive development environment for the Python language with advanced editing, interactive testing, debugging and introspection features
Wing IDE, and probably also other Python IDEs like PyCharm and PyDev have features like this. In Wing you can either select and execute code in the integrated Python Shell or if you’re debugging something you can interact with the paused debug program in a shell (called the Debug Probe). There is also special support for matplotlib, in case you’re using that, so that you can work with plots interactively.
I’m about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs.
I’m looking for an IDE for Python that will give me a lot of the capabilities I’ve grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al.
Have tried many different (Kate, Eclipse, Scite, Vim, Komodo): each one have some glitches, either limited functions, or slow and unresponsive. Final choice after many years: Emacs + ropemacs + flymake. Rope project file open dialog is extremely quick. Rope refactoring and code assist functions are super helpful. Flymake shows syntax mistakes. Emacs is the most configurable editor. I am very happy with this config. Python related part of config is here: public.halogen-dg.com browser/alex-emacs-settings/configs/cfg_python.el
I use TextMate for all my Python programming needs. It’s not an IDE per se, but it does a lot of stuff that an IDE does (without all the cruft of an IDE). It has syntax highlighting, code folding, integration with various SCMs through the use of additional bundles (I know it supports SVN, Git, Mercurial, Darcs, and probably a few others). It’s also quite extensible and customizable (again, through the use of bundles). It also has a basic concept of projects. One place where it doesn’t shine, though, is in code completion; some bundles have limited support for code completion, but it’s generally not as amazing as that of most language-specific IDEs. Given how awesome TextMate is, though, I don’t know sacrificing that. TextMate’s definitely made me much more productive.
I usually use either komodo edit or aquamacs with ropemacs. Although I should warn you, IDE features won’t be what you’re used to if you’re coming from a Java or C# background. I personally find that powerful IDEs get in my way more than they help.
UPDATE: I should also point out that if you have the money Komodo IDE is worth it. It’s the paid version of Komodo Edit.
If you are looking for an interactive environment and not needing to code modules, I would suggest IPython. Though this is developed with scientists/statisticians in mind, it will run just as well without any of the scientific packages installed. The features are powerful, with code completion, integrated help, integrated debugging, etc., and it functions as a notebook with Markdown and MathJax integration. By far the best choice for those that need powerful features without wishing to load megabytes of GUI into RAM–since it is browser based, it is used in your always loaded chrome/safari instance. ;-)
I’ve searched on Google for an app like this for a while, and I’ve found only options with heavy and ugly interfaces.
Then I opened Mac App Store and found CodeRunner. Very nice and clean interface. Support many languages like Python, Lua, Perl, Ruby, Javascript, etc. The price is U$10, but it’s worth it!
“Which editor/IDE for …?” is a longstanding way to start a “My dog is too prettier than yours!” slapfest. Nowadays most editors from vim upwards can be used, there are multiple good alternatives, and even IDEs that started as C or Java tools work pretty well with Python and other dynamic languages.
That said, having tried a bunch of IDEs (Eclipse, NetBeans, XCode, Komodo, PyCharm, …), I am a fan of ActiveState’s Komodo IDE. I use it on Mac OS X primarily, though I’ve used it for years on Windows as well. The one license follows you to any platform.
Komodo is well-integrated with popular ActiveState builds of the languages themselves (esp. for Windows), works well with the fabulous (and Pythonic) Mercurial change management system (among others), and has good-to-excellent abilities for core tasks like code editing, syntax coloring, code completion, real-time syntax checking, and visual debugging. It is a little weak when it comes to pre-integrated refactoring and code-check tools (e.g. rope, pylint), but it is extensible and has a good facility for integrating external and custom tools.
Some of the things I like about Komodo go beyond the write-run-debug loop. ActiveState has long supported the development community (e.g. with free language builds, package repositories, a recipes site, …), since before dynamic languages were the trend. The base Komodo Edit editor is free and open source, an extension of Mozilla’s Firefox technologies. And Komodo is multi-lingual. I never end up doing just Python, just Perl, or just whatever. Komodo works with the core language (Python, Perl, Ruby, PHP, JavaScript) alongside supporting languages (XML, XSLT, SQL, X/HTML, CSS), non-dynamic languages (Java, C, etc.), and helpers (Makefiles, INI and config files, shell scripts, custom little languages, etc.) Others can do that too, but Komodo puts them all in once place, ready to go. It’s a Swiss Army Knife for dynamic languages. (This is contra PyCharm, e.g., which is great itself, but I’d need like a half-dozen of JetBrains’ individual IDEs to cover all the things I do).
Komodo IDE is by no means perfect, and editors/IDEs are the ultimate YMMV choice. But I am regularly delighted to use it, and every year I re-up my support subscription quite happily. Indeed, I just remembered! That’s coming up this month. Credit card: Out. I have no commercial connection to ActiveState–just a happy customer.
You might want to look into Eclim, an Eclipse server that allows you to use Eclipse functionality from within your favorite text editor. For python-related functionality, it uses Rope, PyFlakes, and PyLint under the hood.
I’ve been using an Evaluation copy of Sublime Text. What’s good is it doesn’t really expire.
It’s been good so far and was really easy to get started with.
回答 20
我为此可能会有点晚,但是我建议使用Aptana Studio3.x。它是基于eclipse的,并且可以随时使用python。对DJango, HTML5 and JQuery。对我来说,它是一个完美的Web开发工具。我也从事HTML5 and Android开发工作,因此无需切换其他IDE。这是我的多合一解决方案。
I may be a little late for this, but I would recommend Aptana Studio 3.x . Its a based on eclipse and has everything ready-to-go for python. It has very good support for DJango, HTML5 and JQuery. For me its a perfect web-development tool. I do HTML5 and Android development too, this way I do not need to keep switching different IDE’s. It my all-in-one solution.
Note: you need a good amount of RAM for this to be snazzy !! 4+ GB is awesome !!
It’s lightweight and offers Code Completion. Costs money.
EDIT:
Apparently Chocolat was an interesting option in 2013 but since then many others came up and development stalled. Nowadays I recommend Visual Studio Code + Python Plugin.
I’m very glad you asked! I was just working on explaining this very thing in our wikibook (which is obviously incomplete). We’re working with Python novices, and had to help a few through exactly what you’re asking!
Command-line Python in Windows:
Save your python code file somewhere, using “Save” or “Save as” in your editor. Lets call it ‘first.py’ in some folder, like “pyscripts” that you make on your Desktop.
Open a prompt (a Windows ‘cmd’ shell that is a text interface into the computer):
start > run > “cmd” (in the little box). OK.
Navigate to where your python file is, using the commands ‘cd’ (change directory) and ‘dir’ (to show files in the directory, to verify your head). For our example something like,
> cd C:\Documents and Settings\Gregg\Desktop\pyscripts
try:
> python first.py
If you get this message:
‘python’ is not recognized as an
internal or external command, operable
program or batch file.
then python (the interpreter program that can translate Python into ‘computer instructions’) isn’t on your path (see Putting Python in Your Path below). Then try calling it like this (assuming Python2.6, installed in the usual location):
> C:\Python26\python.exe first.py
(Advanced users: instead of first.py, you could write out first.py’s full path of C:\Documents and Settings\Gregg\Desktop\pyscripts\first.py)
Putting Python In Your Path
Windows
In order to run programs, your operating system looks in various places,
and tries to match the name of the program / command you typed with some
programs along the way.
In windows:
control panel > system > advanced > |Environmental Variables| > system variables -> Path
this needs to include: C:\Python26; (or equivalent). If you put it at the front,
it will be the first place looked. You can also add it at the end, which is possibly saner.
Then restart your prompt, and try typing ‘python’. If it all worked, you should
get a “>>>” prompt.
You can open your .py file with IDLE and press F5 to run it.
You can open that same file with other editor ( like Komodo as you said ) save it and press F5 again; F5 works with IDLE ( even when the editing is done with another tool ).
Python itself comes with an editor that you can access from the IDLE File > New File menu option.
Write the code in that file, save it as [filename].py and then (in that same file editor window) press F5 to execute the code you created in the IDLE Shell window.
Note: it’s just been the easiest and most straightforward way for me so far.
If this helps anyone, neither “python [filename].py” or “python.exe [filename.py]” worked for me, but “start python [filename].py” did. If anyone else is experiencing issues with the former two commands, try the latter one.
What I just did, to open a simple python script by double clicking. I just added a batch file to the directory containing the script:
@echo off
python exercise.py
pause>nul
(I have the python executable on my system path. If not one would need include its complete path of course.)
Then I just can double click on the batch file to run the script. The third line keeps the cmd window from being dismissed as soon as the script ends, so you can see the results. :) When you’re done just close the command window.
Navigate your file location just press Shift button and click file name. Click tab Open command window here and write in your command prompt python file_name.py
If you want to run the #’.py’ file
just write in print() in your code to actually see it get printed.
Unlike python IDLE, you need to specify what you want to print using print() command.
For eg.
import os
os.getcwd()
a=[1,2,3,4,5]
name= 'Python'
# Use print() function
print(a)
print(name)
I have tried many of the commands listed above, however none worked, even after setting my path to include the directory where I installed Python.
The command py -3 file.py always works for me, and if I want to run Python 2 code, as long as Python 2 is in my path, just changing the command to py -2 file.py works perfectly.
I am using Windows, so I’m not too sure if this command will work on Linux, or Mac, but it’s worth a try.
I have done a little Django development, but it has all been in a text editor. I was curious what more advanced development tools others are using in their Django development.
I am used to using Visual Studio for development and really like the IntelliSense, code completion, and file organization it provides and would like to find something (or a combination of tools) that would provide some of this in the Django/Python environment.
I use Eclipse and a plain vanilla PyDev. There isn’t any specific Django functionality. The best I came up with was setting up a run profile to run the development web server.
If you add the web tools project (WTP), you’ll get syntax highlighting in your templates, but nothing that relates to the specific template language. PyDev is a decent plugin, and if you are already familiar with Eclipse and use it for other projects it is a good way to go.
I recall NetBeans starting to get Python support, but I have no idea where that is right now. Lots of people rave about NetBeans 6, but in the Java world Eclipse still reigns as the king of the OSS IDEs.
I am beginning to enjoy working with Aptana Studios + PyDev (and other) plugins for all sorts of web application development. As you can tell, it is built on top of the powerful Eclipse, but is tailor-designed to focus on web application development.
I use Kate (KDE Advanced Text Editor) for most of my development, including Django. It has both a Python and Django Templates syntax higlighting. I switch to Quanta+ when a significant part of the project involves HTML.
Since it uses Kate’s KPart, it’s just as good for editing the Python parts, and for the HTML templates i have the whole Quanta+ tools, while still highligting Django-specific tags.
Update 2013: Unfortunately, Quanta+ has been dead for years now, and there’s no hope that it will ever be resurrected. Also, there’s no other usable HTML editor out there, so it’s Kate all the time now.
NetBeans for Python is my current favorite (lighter and so much easier to install than Eclipse I found). Supports simple refactoring, autocompletion, errors/warnings…
EclipseAptanaPyDev probably one of the most complete free IDE nowadays (haven’t tested a lot)
Wingware Python IDE a commercial IDE, which has some Django-specific project setup features the ability to debug Django template files.
IntelliJ IDEAUltimate Edition another commercial IDE which has also a plugin for Python that is under heavy development. I saw some demo which look very promising on the auto-completion (for templates and Python).
As far as I know there is not “an IDE” for Django, but there are some IDEs that support Django right out of the box, specifically the Django syntax for templates.
The name is Komodo, and it has a lot of features, but it’s not cheap. If you are not worried about source control or debugging then there is a free version called Komodo Edit.
There is an actual Python extension for Visual Studio: http://pytools.codeplex.com/. It’s absolutely fantastic. It feels the same as if I were coding in any native Visual Studio language. The extension is even compatabile with Django. And best of all: it’s totally free. Even for Visual Studio, it only requires the Visual Studio Shell to work, which is completely free.
Create a new project from existing code (menu File → New → Project From Existing Code…)
Specify your Django project folder and use the defaults.
Right-click on manage.py and choose Set as Startup File.
In your project properties Debug tab, add “runserver” in Script Arguments.
You can set break points, and attach to the Python process for debugging. If you want to debug without having to “attach to process,” use “runserver –noreload” in your script arguments. However, the “–noreload” means you’ll have to stop and restart the Django development web server manually (to recognize your code changes).
This is a nice setup if you already use Visual Studio.
Python Tools has been updated. It has built in support for Django now.
I have used Eclipse with PyDev and PyCharm. PyCharm is definitely the best IDE for Django/Python I have tried. It does proper template highlighting and auto-completion for all objects. It also does cross-file referencing.
I’ve also had good results with Eclipse and Pydev. Although I still require a shell opened to the project directory to run manage.py commands. I’ve also been using it with the Bazaar plugin for revision control and syncing code with the server.
回答 18
我非常喜欢E Text Editor,因为它几乎是TextMate与Windows 的“连接” 。显然Django是基于Python的,对自动完成功能的支持是有限的(没有像intellisense这样的东西需要专门的IDE来了解每个库的复杂性),但是使用摘要和“单词完成”功能有很大帮助。此外,它还支持Django Python文件和模板文件以及CSS,HTML等。
我已经使用E Text Editor很长时间了,可以告诉您,在使用Django时,它胜过PyDev和Komodo Edit。对于其他类型的项目,PyDev和Komodo可能更合适。
I really like E Text Editor as it’s pretty much a “port” of TextMate to Windows. Obviously Django being based on Python, the support for auto-completion is limited (there’s nothing like intellisense that would require a dedicated IDE with knowledge of the intricacies of each library), but the use of snippets and “word-completion” helps a lot. Also, it has support for both Django Python files and the template files, and CSS, HTML, etc.
I’ve been using E Text Editor for a long time now, and I can tell you that it beats both PyDev and Komodo Edit hands down when it comes to working with Django. For other kinds of projects, PyDev and Komodo might be more adequate though.
I use Kate as well. Kate’s simplicity is its biggest feature. It doesn’t get in your way. (This is of course highly subjective opinion.)
Kate includes a Python code browser plugin. But it isn’t useful IMO. No automatic updates when you change the code/view. Also when you update, the whole tree is collapsed, and you have to expand it again yourself. Too many clicks.
Instead, I use the Source Browser plugin that comes with Pâté. It does cause Kate to freeze temporarily sometimes, but no crashes or anything of that sort so far.
I made a blog post about NetBeans’ new and upcoming support for Django. When paired with its already fantastic Python, JavaScript, HTML and CSS support, it’s a strong candidate in my mind!
TextMate with the Django and django-html bundles installed gives you syntax highlighting and great extensibility. It is lightweight and fun to use.
Here is a link to a code completion project for TextMate with Python (which I haven’t used myself). As for “intellisense” (which I understand to be inline-doc reference), TextMate has that too.
The Wingware editor from http://www.wingware.com is Python-specific with very good auto-completion for Python/Django/Zope, etc.
It has a built in Python shell to run snippets (or select and run) and support for Mercurial/Git, etc. and a built-in unittest/nose/doctest test runner. It’s commercial though, but as it is written in Python, it’s cross platform.
I bought it a while ago, and thought it looked dorky, but I’ve tried them all and keep coming back. Caveat that I am a Windows guy with no Emacs or Vim skills, so leveraging that was not an option. And the Mac version requires X Window and seems to be more glitchy.
But when CtrlBdoes not work, Sublime Text probably can’t find the Python Interpreter. When trying to run your program, see the log and find the reference to Python in path.
The point is that it tries to run python via command line, the cmd looks like:
python -u C:\scripts\test.py
If you can’t run python from cmd, Sublime Text can’t too.
(Try it yourself in cmd, type python in it and run it, python commandline should appear)
SOLUTION
You can either change the Sublime Text build formula or the System %PATH%.
To set your %PATH%:
*You will need to restart your editor to load new %PATH%
Run Command Line* and enter this command: *needs to be run as administrator SETX /M PATH "%PATH%;<python_folder>"
for example: SETX /M PATH "%PATH%;C:\Python27;C:\Python27\Scripts"
OR manually: (preferable)
Add ;C:\Python27;C:\Python27\Scripts at the end of the string.
To set the interpreter’s path without messing with System %PATH% see this answer by ppy.
It explains (like one of the answers above) how to edit this exec.py in the default directory.
I had the problem that my PYTHON UI APPLICATION would not start. I commented out the last line from the following snipped:
# Hide the console window on Windows
startupinfo = None
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
#startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
and, taaadaaaa, I could start my app by pressing Ctrl+B. Funny line anyways, uh? And a big thank you to whoever wrote that article ;-)
One thing to note about the aforementioned build system: you can write (and use) custom .sublime-build files or even per project build_systems clause (in your project settings). This allows you to do useful things like a fancy test runner with ANSI colors output.
For even more “full IDE” features, you can use the excellent SublimePythonIDE package:
code completion (intel)
jump to definition & object description
proper linting/pep8
supports different interpreters with virtualenv
Disclosure: I’ve contributed a PR to that package, and I use it all the time, but thereareothers.
Both Sublime’s build system and SublimeREPL (the answers above) are limited in that you can’t easily interact with the workspace variables after you run your file.
If you want to run a script, then work in a REPL-like fashion (like you would in an IDE), then I recommend having Sublime open alongside an IPython console. Using AutoHotKey (Windows) or AutoKey (Linux), you can set this up such that a single shortcut will copy the filename (or just the selected code) and then paste this in the console to run the file.
Manually adding it as you have done is indeed one way of doing this, but there is a simpler method, and that is by simply telling pycharm that you want to add the src folder as a source root, and then adding the sources root to your python path.
This way, you don’t have to hard code things into your interpreter’s settings:
Add src as a source content root:
Then make sure to add add sources to your PYTHONPATH:
Now imports will be resolved:
This way, you can add whatever you want as a source root, and things will simply work. If you unmarked it as a source root however, you will get an error:
After all this don’t forget to restart. In PyCharm menu select: File –> Invalidate Caches / Restart
If anyone is still looking at this, the accepted answer still works for PyCharm 2016.3 when I tried it. The UI might have changed, but the options are still the same.
ie. Right click on your root folder –> ‘Mark Directory As’ –> Source Root
Generally, this is a missing package problem, just place the caret at the unresolved reference and press Alt+Enter to reveal the options, then you should know how to solve it.
Chose the directory/project where your file that has unresolved imports resides and check the box to tell Pycharm that that project depends on your other project.
My folder hierarcy is slightly different from the one in the question. Mine is like this
Install via PyCharm (works with Community Edition). Open up Settings > Project > Project Interpreter then click the green + icon in the screenshot below. In the 2nd dialogue that opens, enter the package name and click the ‘Install Package’ button.
Please check if you are using the right interpreter that you are supposed to. I was getting error “unresolved reference ‘django’ ” to solve this I changed Project Interpreter (Changed Python 3 to Python 2.7) from project settings:
Select Project, go to File -> Settings -> Project: -> Project Interpreter -> Brows and Select correct version or Interpreter (e.g /usr/bin/python2.7).
In my case the problem was I was using Virtual environment which didn’t have access to global site-packages. Thus, the interpreter was not aware of the newly installed packages.
To resolve the issue, just edit or recreate your virtual interpreter and tick the Inherit global site-packages option.
回答 12
这为我工作: Top Menu -> File -> Invalidate Caches/Restart
Pycharm uses venv. In the venv’s console you should install the packages explicitly or go in settings -> project interpreter -> add interpreter -> inherit global site-packages.
In newer versions of pycharm u can do simply by right clicking on the directory or python package from which you want to import a file, then click on ‘Mark Directory As’ -> ‘Sources Root’
L - Linux
W - Windows
M - Mac
C - Commercial
F - Free
CF - Commercial with Free limited edition
? - To be confirmed
I don’t mention basics like syntax highlighting as I expect these by default.
This is a just dry list reflecting your feedback and comments, I am not advocating any of these tools. I will keep updating this list as you keep posting your answers.
PS. Can you help me to add features of the above editors to the list (like auto-complete, debugging, etc.)?