Master PyCharm: From Installation to Advanced Features for Python Development
This comprehensive tutorial walks you through installing PyCharm, creating and running Python projects, debugging, testing, navigating large codebases, integrating version control, using plugins and external tools, and exploring professional features like Django support, all illustrated with step‑by‑step screenshots and shortcuts.
PyCharm Installation
PyCharm Community Edition 2019.1 can be installed via the JetBrains Toolbox App, which simplifies installing, updating, and removing JetBrains products. After launching the Toolbox, select PyCharm Community and click Install . Accept the user agreement, then the IDE is ready.
On first launch, PyCharm shows an import settings dialog; choose Do not import settings , keep the default keymap, and select a UI theme (the tutorial uses the Darcula dark theme).
Writing Code in PyCharm
Create a new project via File → New Project . Choose a location, select a Python interpreter (the tutorial uses a virtualenv based on Python 3.6), and keep the default settings. Click Create to open the project.
After the project opens, create a new Python file (e.g., guess_game.py) using Cmd+N (macOS) or Alt+Ins (Windows/Linux). Write the following simple guessing‑game code:
import random
random_int = random.randint(1, 100)
while True:
user_guess = int(input("Guess a number: "))
if user_guess == random_int:
print("Congratulations! You guessed it.")
break
elif user_guess < random_int:
print("Too low!")
else:
print("Too high!")Running Code
The program can be executed in three ways:
Press Ctrl+Shift+R (macOS) or Ctrl+Shift+F10 (Windows/Linux).
Right‑click the editor background and choose Run 'guess_game' .
Click the green arrow next to the __main__ block.
The Run tool window displays the program’s output.
Debugging
Set a breakpoint on line 8 (the if statement) by clicking the gutter. Use one of the following to start debugging:
Ctrl+Shift+D (macOS) or Shift+Alt+F9 (Windows/Linux).
Right‑click the background and select Debug 'guess_game' .
Click the green arrow next to the __main__ block and choose Debug .
The Debugger window shows variable values (e.g., random_int). Step through the code with F8 (step over) or F7 (step into). Use the Console tab to interact with the program during debugging.
Fix the bug by changing the erroneous randint comparison to random_int, then re‑run the debugger to verify the corrected flow.
Testing
PyCharm supports several test frameworks; the tutorial uses the built‑in unittest. Create calculator.py with a simple Calculator class, then generate a test file via Shift+Cmd+T (macOS) or Ctrl+Shift+T (Windows/Linux) or via the Navigate → Test menu.
Run the tests using Ctrl+R (macOS) or Shift+F10 (Windows/Linux), or via the Run context menu. The test runner shows passed and failed tests, and you can filter, sort, or ignore tests directly from the UI.
Editing Existing Projects
Open an existing project via File → Open or the welcome screen. PyCharm automatically detects a virtual environment and sets it as the project interpreter. You can change the interpreter later in Settings/Preferences → Project → Project Interpreter .
Search and Navigation
Use Cmd+F / Ctrl+F to search within the current file, Cmd+Shift+F / Ctrl+Shift+F for a project‑wide search, Cmd+O / Ctrl+N to find a class, and Cmd+Shift+O / Ctrl+Shift+N to locate a file. Press Shift twice to invoke the universal search.
Go to declaration: Cmd (macOS) or Ctrl (Windows/Linux) + click.
Find usages: Alt+F7 .
Recent changes: Shift+Alt+C or View → Recent Changes .
Recent files: Cmd+E (macOS) or Ctrl+E (Windows/Linux).
Navigate back/forward: Cmd+[ / Cmd+] (macOS) or Ctrl+Alt+Left / Right (Windows/Linux).
Version Control Integration
PyCharm integrates with Git, Mercurial, Perforce, and Subversion. Enable VCS via VCS → Enable Version Control Integration… and select Git . The VCS Operations Popup then provides shortcuts for add, commit, push, etc.
Commit changes via Cmd+K (macOS) or Ctrl+K (Windows/Linux). Resolve merge conflicts using the built‑in merge tool, which shows your changes, the incoming changes, and the merged result.
Plugins and External Tools
Extend PyCharm’s functionality via the Marketplace. Popular plugins include IdeaVim (Vim emulation), Material Theme UI (dark UI), Vue.js , and Markdown . Install plugins via Settings/Preferences → Plugins → Marketplace .
External tools such as flake8 can be added under Settings/Preferences → Tools → External Tools . Define the program path, arguments (e.g., $FileName$), and working directory. Optionally assign a keyboard shortcut via Keymap → External Tools .
Professional Features
PyCharm Professional adds built‑in support for Django, database tools, thread‑concurrency visualization, profiling, and scientific mode. Enable Django support via Settings → Languages & Frameworks → Django → Enable Django support . The IDE then provides template completion, ORM navigation, and manage.py integration.
Database tools (based on DataGrip) support MySQL, PostgreSQL, SQLite, Oracle, and more, allowing you to run queries, edit schemas, and view data directly from the IDE.
Thread Concurrency Visualization helps debug asynchronous code (e.g., asyncio, Django Channels). Profiling can be performed with vmprof, yappi, or the built‑in cProfile to identify performance bottlenecks.
Conclusion
PyCharm is a powerful, feature‑rich IDE for Python development. By following this tutorial you should now be able to install the IDE, create and run projects, debug efficiently, write and run tests, navigate large codebases, integrate version control, extend functionality with plugins, and leverage professional tools for web and scientific development.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
