Learn Basics of Integrated Development Environment
A Few Pointers on How to Get by in Pycharm Ide
In this post you should learn some absolute basics of PyCharm to allow you to start developing code without any issues using it.
Once PyCharm has loaded it will give you a choice to make a new project. Select that. You will see a window like the one below.
Make sure you choose a location and name of your project as you wish. Also since you have already installed Python 3 it should automatically get selected for you as the project’s interpreter – if there is nothing to select you have probably not added Python to your system environment variables (PATH) or it is not installed at all.
Here you can also create a virtual environment based on the Python 3 that is installed but we will do that once we get into the editor.
Click create and see what the editor looks like.
Now before you open any files it’s best to finish setting stuff up. Just a few checks and we are good to go.
Set Number of Characters in Line to 80
Go to: File -> Settings -> Editor -> Code Style and set the right margin (columns) to 80 as per Python’s code style guidelines.
This will help you to place 2 or 3 files of code in vertical split next to each other .
Choose Your Default Unit Testing Framework and Docstrings Code Style
Now visit: File -> Settings -> Editor -> Tools -> Python Integrated Tools and choose:
- default test runner: py.test (don’t worry when it says below it cannot find it in the interpreter – we will install it in a sec). This will allow us to write easy unit tests for our code in a minute.
- docstring format: Google (or Numpy / reStructured) – you have to document your code properly. This setting helps a lot in making unified docstrings across entire project.
Select Project’s Python Interpreter
Next step is to set up project interpreter. Go to: File -> Settings -> Project: <Your project’s name> -> Project interpreter and click a cog (settings) icon. You will be presented with Python interpreters to choose from. Select “create virtual environment”. I recommend storing all your environments in one place. On Ubuntu I keep them in home/<user>/.virtualenvs on windows in C:\Users\<user>\Envs. Name your virtual environment to reflect project you will work on. This will make it easier later on to figure which environment you can delete when not needed.
Install Pytest – Unit Testing Framework
Next we will install pytest as our default unit testing library. Click “Terminal” tab at the bottom-left side of the PyCharm’s window. Notice that your newly created virtual environment is already activated for you – you should see its name in brackets on the left side of the command prompt. Type: pip install pytest. This will install pytest – a great unit testing library in your virtual environment (and not in the main Python’s installation). This way we avoid polluting main Python’s install with all our libraries for various projects.
With all that work done you can create your first python file and start coding.
Go to: File -> New -> Python File and add some code! You may want to play with other settings but what we just did should be enough to get you going.