I have been in Python for about 7 years now and have changed various development environments such as PyScripter and Vim. I assert that ** PyCharm is the strongest Python development environment **.
Developed by JetBrains of IntelliJ IDEA, it recently announced Gogland, an IDE for the Go language. The operating environment is Windows / OS X / Linux multi-platform. There are free and paid versions of PyCharm, but for normal development, the free version is more than enough.
Let me show you how useful PyCharm is.
PyCharm checks the code in real time (using PyFlakes), but Vim can do the same, so it's not new. The great thing about PyCharm is that it has a feature that ** fixes warnings properly **.
For example, suppose you write code like this:
member = {}
member["name"] = "Tim"
member["age"] = 32
member["sex"] = "men"
PyCharm warns you with a wavy line in the bad part.
I don't know what you're saying, but let's move the cursor to the wavy line and press "Alt + Enter" (for Windows).
It will suggest a solution to the warning, so select "Replace dictionary creation".
members = {"name": "Tim", "age": 32, "sex": "men"}
Redundant variable declarations and initializations over multiple lines have been optimized for one sentence. As you can see, PyCharm can do something about it by pressing "Alt + Enter" when you are in trouble.
Another thing that is sober and convenient is that it has an English dictionary that points out misspellings of words and mistakes in plural forms **.
The figure above is an example where it is pointed out that the plural form of "property" is to be written as "propertys" (correctly "properties"). Thanks to this warning feature, I haven't committed several embarrassing English word mistakes.
If you want to inspect all the codes at once, you can select "Code"-> "Inspect Code ..." from the menu to inspect all the codes at once.
Python is, needless to say, a dynamically typed language. It is also a fact that completion is difficult to work because it is a dynamically typed language, and an error occurs because an invalid type is specified for the argument. PyCharm allows type hinting to pre-type check ** like a statically typed language.
For example, suppose you have defined a function `get_digit``` that finds the digits of a number, the argument accepts ```int``` or
float```. If ``
str or `` `list
is specified as an argument, TypeError will occur.
def get_digit(x):
digit = 0
while x > 0:
x //= 10
digit += 1
return digit
Execution result
get_digit(130)
>>> 3
get_digit(130.0)
>>> 3
get_digit("text")
>>> TypeError
Let's describe PyCharm type hinting. If you move the cursor to an argument or function and press "Alt + Enter", a template for type hinting will be generated, so it is very easy to describe.
The code that describes type hinting is below.
def get_digit(x):
"""
:type x: int or float
:rtype: int
"""
digit = 0
while x > 0:
x //= 10
digit += 1
return digit
After writing type hinting, I get a warning when I try to pass a string to `` `get_digit```.
I don't write function comments, but only type hinting. (A spirit that does not require comments if the naming is appropriate)
By the way, if you want to set type hinting for class members, write as follows.
class A(object):
"""
:type name: basestring
:type description: basestring or None
"""
def __init__(self, name):
self.name = name
self.description = None
With PyCharm, Python becomes ** the strongest language for dynamically and statically typed languages **. It also supports type annotations introduced in Python 3.5.
For more information on type hinting, see Jet Brains Help below. Type Hinting in PyCharm
The search window that appears when you press Shift
twice is quite convenient.
With this alone, all searches, including files, classes, methods, members and variables, are aggregated here.
There is also a Ctrl + Shift + F
grep search, you only have to remember two functions to search for code
It also displays a list of TODO comments written in the source by selecting "View"-> "Tool Windows"-> "TODO Alt + F6" from the menu.
There is a function that displays a TODO list with CI using Jenkins etc., but this is convenient because it can be executed locally without preparing a server.
The refactoring function is also substantial.
Despite being a dynamically typed language, variable names and member name renaming are ** renamed in a nice way ** in consideration of scope. Of course, since it is a dynamically typed language, member names may not be renamed correctly. Type hinting should be described as much as possible to improve the accuracy of refactoring.
There is also a template for frequently used files. UnitTest and SetupScript templates are also provided as standard, so the load of creating UnitTest and setup.py is greatly reduced.
Of course, you can also set your own template. It can be edited from "New"-> "Edit File Templates ..." from the right-click menu.
Of course, template variables are also prepared, so dates and creators can be inserted automatically.
I am developing PySide / PyQt and registering a UI form file. For details, see ["Add" Qt UI Designer Form "to the #file template where the strongest PySide / PyQt development environment is also PyCharm"](http://qiita.com/pashango2/items/5d3c278f05ad151bfd5a#%E3%83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 83% 86% E3% 83% B3% E3% 83% 97% E3% 83% AC% E3% 83% BC% See E3% 83% 88% E3% 81% ABqt-ui-designer-form% E3% 82% 92% E8% BF% BD% E5% 8A% A0% E3% 81% 99% E3% 82% 8B) I want you to.
For more information on file templates, see Jet Brains Help below. Creating and Editing File Templates
It has abundant debugging functions and you can think that you can almost do basic things.
--Installation of breakpoints --Installation of conditional breakpoints --Watch type
The figure below shows the editor display during debugging, where the current value is displayed next to the variable, making the information very easy to see.
By the way, it is a method of setting a conditional breakpoint, but since the setting screen appears by right-clicking the breakpoint, just write the conditional expression in "Condition".
After all, if the debugger can be operated with the GUI, the debugging efficiency will increase dramatically. PyCharm cannot be parted with because a debugger is required for a large project to some extent.
It is linked with VCS (version control system) such as Git and Mercurial, and simple operations such as adding files can be performed on PyCharm.
In particular, tracked, untracked, and uncommitted files are color-coded, so it's useful to know the commit status at a glance.
If you want to check the history of VCS easily, you can check it from PyCharm as shown in the figure below.
PyCharm also supports Anaconda's virtual environment. Menu "File"-> "Settings"-> "Project Interpreter" You can set up a Python environment for each project.
My environment is Miniconda (the smallest version of Anaconda), which is a mixture of Python 2.7 / 3.4 / 3.5 and three Python virtual environments.
So I created a Python root directory and created a project for each Python version. Sample code and each product are managed as subprojects. It is convenient because you can browse the products and sample code that you have written up to now in a tree shape on PyCharm.
Python directory structure
Python/
├ Python35/
| ├ project a
| ├ project b
| └ moules
|
├ Python34/
| ├ project a
| ├ project b
| └ moules
|
└ Python27/
├ project a
├ project b
└ moules
By doing this, you can switch the virtual environment just by switching the PyCharm project without typing the "activate / deactivate" command.
The project structure settings can be set by right-clicking the directory menu "Mark Directory as"-> "Sources Root". If set to "Sources Root", that directory will be treated as the root of the subproject.
For more information on structuring the project, see Jet Brains Help below.
It can also be linked with Jupyter Notebook (IPython) from PyCharm, and can be created with the right-click menu "New"-> "Jupyter Notebook".
Code completion uses PyCharm's, so it's more comfortable than running in a browser. However, it's a pity that the keyboard shortcuts created by Jupyter cannot be used.
I often use Jupyter Notebook to test image processing with PIL, but when I launch "Jupyter Notebook" from the command line on Windows, I'm freed from the phenomenon that the unused Microsoft Edge starts up.
For the cooperation with Jupyter, refer to the Jet Brains help below.
Using IPython/Jupyter Notebook with PyCharm
IntelliJ IDEA, which is the basis of PyCharm, has a wealth of plugins that you can use with PyCharm.
A useful plugin I use with PyCharm is a plugin called File Watchers
. It is a task runner that monitors files and automatically executes commands when updating.
I am automatically converting PySide / PyQt ui files. For details, see ["The strongest PySide / PyQt development environment is also PyCharm. #Ui files are automatically converted to py files"](http://qiita.com/pashango2/items/5d3c278f05ad151bfd5a#ui%E3%83%95 % E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 82% 92% E8% 87% AA% E5% 8B% 95% E7% 9A% 84% E3% 81% ABpy% E3 Please refer to% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 81% AB% E5% A4% 89% E6% 8F% 9B).
See also Jet Brains help below.
PyCharm has so many features that I can't cover here, and there are probably more useful features I don't know about. I think people who use Python but not PyCharm are losing a lot.
Especially since code completion is great, I want Python beginners to use PyCharm. It's a really great tool.
I wrote the continuation of the article, "PyCharm operation rules I practice".
In addition, I will add an article that conveys the charm of PyCharm.
[PyCharm 5.0 new function] Visualize and debug the thread execution status of async / await
"Generate Jupyter notebook" .ipynb "in Python"
IntelliJ IDEA Shortcuts for Busy People (´-`)
Unexpectedly unknown IntelliJ IDEA Git management functions (´-`)
Recommended Posts