Master PyCharm: Install, Code, Debug, Test, and Deploy Python Projects
This comprehensive tutorial walks you through installing PyCharm Community or Professional, creating and configuring Python projects, writing and running code, debugging, unit testing, version control integration, using plugins, and leveraging advanced features such as remote development and profiling, all illustrated with screenshots for macOS, Windows, and Linux.
PyCharm is a powerful IDE and the de‑facto choice for Python development. This tutorial assumes you have Python installed (Python 3.6 is used in the examples) and runs on macOS, with notes for other platforms.
1. Installing PyCharm
The tutorial uses PyCharm Community Edition 2019.1 (free) and mentions that the final part about Professional features requires PyCharm Professional Edition 2019.1.
It is recommended to install PyCharm via the JetBrains Toolbox App, which lets you manage multiple JetBrains products and versions. The Toolbox App provides platform‑specific installation instructions.
After installing, launch the app, accept the user agreement, and under Tools you will see a list of available products. Choose PyCharm Community and click Install . If you prefer not to use the Toolbox, you can install PyCharm directly.
When you start PyCharm for the first time, you will see an import settings dialog. Choose Do not import settings , keep the default keymap, and select the UI theme (the tutorial uses the Darcula dark theme).
2. Writing Code
To create a new project, click Create New Project on the welcome screen. Specify the project location and configure the Project Interpreter. You can create a new virtual environment (Virtualenv, Pipenv, or Conda) or use an existing interpreter. The tutorial selects Virtualenv and leaves the default options unchecked.
After the project is created, close the "Tip of the Day" dialog. Create a new Python file (e.g., guess_game.py) via Cmd+N (macOS) or Alt+Ins (Windows/Linux). The tutorial then shows a simple number‑guessing game where the program picks a random integer and the user tries to guess it, with feedback on each guess.
3. Running Code
The program can be run in three ways:
Press Ctrl+Shift+R (macOS) or Ctrl+Shift+F10 (Windows/Linux).
Right‑click the background and choose Run 'guess_game' .
Click the green run arrow next to the if __name__ == '__main__' line.
The output appears in the Terminal pane at the bottom.
4. Debugging Code
Set a breakpoint on line 8 by clicking in the gutter. Start debugging via Ctrl+Shift+D (macOS) or Shift+Alt+F9 (Windows/Linux), or use the right‑click Debug option. The Debug window shows variable values (e.g., random_int) and lets you step through code with F8 (step over) and F7 (step into). The tutorial demonstrates fixing a bug where the code compares the user guess to the function randint instead of the generated random_int.
5. Testing Code
PyCharm supports unit testing out of the box using unittest, and also integrates with pytest, nose, doctest, tox, and trial. The tutorial shows how to set pytest as the default test runner via Settings → Tools → Python Integrated Tools.
It creates a calculator.py file with a Calculator class, then generates a test file test_calculator.py using the Go To → Test action. Tests are run via Ctrl+R (macOS) or Shift+F10 (Windows/Linux) or the green run arrow. The tutorial demonstrates a failing test, fixing the code, and re‑running to see a passing test.
6. Working with Larger Projects
For larger codebases, open an existing project via File → Open or the welcome screen. PyCharm will detect virtual environments and use them as the project interpreter. You can change the interpreter in Settings → Project → Project Interpreter, adding a new virtualenv if needed.
7. Search and Navigation
PyCharm provides powerful search and navigation shortcuts:
Cmd+F / Ctrl+F : Find in current file.
Cmd+Shift+F / Ctrl+Shift+F : Find in whole project.
Cmd+O / Ctrl+N : Find a class.
Cmd+Shift+O / Ctrl+Shift+N : Find a file.
Press Shift twice to search everywhere.
Navigate to a variable’s declaration with Cmd (macOS) or Ctrl (Windows/Linux) + click.
Find usages with Alt+F7 .
View recent changes with Shift+Alt+C or via View → Recent Changes .
View recent files with Cmd+E / Ctrl+E .
Navigate back/forward with Cmd+[ / Cmd+] (macOS) or Ctrl+Alt+Left / Right (Windows/Linux).
8. Configuring Version Control (VCS)
Open the VCS Operations Popup via VCS → VCS Operations Popup… or Ctrl+V (macOS) / Alt+` (Windows/Linux). Choose Enable Version Control Integration… and select Git . PyCharm will then show Git actions such as add, commit, push, branch, and stash.
9. Commit and Conflict Handling
Commit changes via VCS → Commit… or Cmd+K / Ctrl+K . The Commit dialog lets you select files, write a commit message, run checks, view diffs, and optionally Commit and Push . For merge conflicts, use VCS → Git → Resolve Conflicts… , select the conflicted file, and merge using the three‑pane view (yours, theirs, result). Accept or reject changes with the arrow buttons and apply.
10. Plugins and External Tools
PyCharm’s functionality can be extended with plugins (e.g., IdeaVim, Material Theme UI, Vue.js, Markdown). Install plugins via Preferences → Plugins (macOS) or Settings → Plugins (Windows/Linux). For external tools like flake8, install the package in your virtual environment, then add it under Settings → Tools → External Tools , specifying the program path, arguments (e.g., $FileName$), and working directory. You can assign a shortcut (e.g., Ctrl+Alt+A ) to run the tool quickly.
11. PyCharm Professional Features
The Professional edition adds advanced capabilities such as full Django support. Enable Django via Preferences → Languages & Frameworks → Django and check Enable Django support . PyCharm then provides Django‑specific code insight, templates, ORM navigation, and management commands.
12. Database Support
Through the built‑in Database tools and SQL plugin (enabled by default), PyCharm can work with MySQL, PostgreSQL, SQL Server, SQLite, MariaDB, Oracle, Cassandra, and more. You can browse, query, and manage databases directly from the IDE.
13. Thread Concurrency Visualization
For asynchronous Python (e.g., Django Channels, asyncio, Starlette), the Thread Concurrency Visualization tool helps you understand and debug multithreaded code.
14. Profiler
PyCharm integrates profilers such as vmprof, yappi, and cProfile. If the first two are unavailable, it falls back to cProfile to show which parts of your code consume the most time.
15. Scientific Mode
Python’s data‑science stack (NumPy, SciPy, scikit‑learn, Matplotlib, Jupyter) is supported via Scientific Mode, which offers interactive plots, variable explorers, and notebook‑style execution.
16. Remote Development
You can configure a remote interpreter (e.g., on a Linux VM) to debug code in an environment that matches production, reducing environment‑related bugs.
PyCharm is one of the best Python IDEs, offering many productivity‑boosting features that save time on routine tasks.
Original article: https://blog.csdn.net/algorithmPro/article/details/106596084
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
