How to Use PyCharm for Python
PyCharm is the one of the most popular IDE for Python. It includes features such as code completion and inspection with advanced debugger and support for web programming and various frameworks.
Creating a Python project
Let’s see how we can PyCharm for running a Python script
So first let’s create a project. If you’re on the Welcome screen, click New Project. If you’ve already got a project open, choose File -> New Project. Choose Pure Python, since we are just creating a simple python script. Specify the project location, for that click button next to the Location field, and specify the directory for your project. Also, deselect the Create a main.py welcome script checkbox because you will create a new Python file for this example.
It is better to create a virtualenv for each project. To do that, expand the Python Interpreter: New Virtualenv Environment node and select a tool used to create a new virtual environment. Choose Virtualenv tool, and specify the location and base interpreter used for the new virtual environment. Select the two check boxes below if necessary. When configuring the base interpreter, you need to specify the path to the Python executable. If PyCharm detects no Python on your machine, it provides two options: to download the latest Python versions from python.org or to specify a path to the Python executable (in case of non-standard installation).
Then click the Create button at the bottom of the New Project dialog. Now our project is been created
Creating a Python file
Select the project root in the Project tool window, then select File -> New … from the main menu or press Alt+Insert. Choose the option Python file from the popup, and then type the new filename.
A new Python file is created on PyCharm. Now you can enter your Python code here.
Running your Python file
You can right-click the editor, and from the context menu choose to run the script Ctrl+Shift+F10, but we suggest a better solution: since our script contains a main function, there is an icon in the gutter. If you hover your mouse pointer over it, the available commands show up. Choose Run filename. Now A console appears in the Run tool window.