PyCharm setup
Although you don’t need an IDE (Integrated Development Environment) to program in most languages, they can offer a lot of shortcuts and assistance. I have been asked to do some Python work for a client. It’s not the language I am most familiar with, but have used it professionally in the past.
One thing I am very glad about is the ability to use PyCharm from JetBrains as my IDE. This is going to be a short and simple post outlining how to get started using PyCharm with my installed version of Python controlled by pyenv, which I covered in a previous python setup post.
Installing PyCharm
There are two versions of Pycharm, professional and community editions. As the name suggests the professional edition is a paid version that contains everything the community edition does, with the addition of features. These include support for Scientific Python, HTML, JavaScript and SQL. It saves you from having to jump between IDEs if you are working on a web project with a Python backend.
The community edition is free and supports Python development. For getting started and most simple Python projects it’s perfect and what I’ll be covering in this article.
You can download PyCharm Community directly from the JetBrains site and runs on Windows, Mac and Linux. I’ll be installing it on Mac. Alternatively, if you wish to use multiple JetBrains products, it’s easier to install their free Toolbox that allows for easy updates and additions.
PyCharm setup to include you pyenv Python version
Once you have installed PyCharm and accepted the terms and conditions you with be shown the Welcome to PyCharm window.
We are going to start a New Project and configure it to use our desired version of Python via our pyenv installation.
By default PyCharm will save your projects in the PyCharmProjects folder that it created when it was installed. This is a perfectly valid location, but I tend to save all of my development work in a folder called ‘dev’ so I can keep track of everything I work on regardless of the IDE I used to last work on it with.
PyCharm allows us to easily create a Virtualenv for our project when we create it. I strongly advise that you always use a virtual environment when working with Python. I have covered how you can create a Virtualenv using pyenv on the command line, but you can also have PyCharm do it here for you. Your choice.
For a brand new project select ‘New environment using Virtualenv and select the version of Python you wish to use from your pyenv installation. This is done in the ‘Base interpreter’ selector.
Select the ellipses icon on the right-hand side of the base interpreter dropdown. Our pyenv installation resides in a hidden folder which is indicated by a full stop prefixed to its folder name (Mac and Linux). Therefore by default, it will not show up in the available list of folders. You have to manually type ‘.pyenv’ in the search field before it will appear.
You then need to navigate to the version of the Python interpreter you wish to use in this project. For my example I have installed Python 3.9.0 and would find this on the path:
/Users/robertmcbryde/.pyenv/versions/3.9.0/bin/python
You should now be good to run your Python code.
You can change the Python interpreter anytime under PyCharm > Preferences > Project: > Python Interpreter