PyCharm Linux Setup


Installing PyCharm for Linux

Installing Python

In order to be able to run Python programs on your computer, you need to install a Python Interpreter. An interpreter is a program that is capable of reading a .py file that you have written, and translating the Python code in that file to instructions that your computer can easily execute. There is likely already a Python interpreter on your computer, but it may be Python 2 instead of Python 3, which we require for CS106A.

Installing Python on Linux

CS 106A requires the use of the newest version of Python, so make sure to follow these instructions even if you think you already have Python installed. To install Python3.9 (the version we are using in class), open a Terminal. If you are using a Debian-based Linux version (such as Ubuntu), type:

sudo apt install python3.9

If you are using a Fedora-based Linux version (such as CENTOS), type:

sudo yum install python3.9

If the above commands don't work, you may need to manually compile Python3.9. Please email Chris to set up a meeting if you are having trouble.


Installing and Testing PyCharm

Installation

To perform the installation, open a terminal and perform the following steps:

cd ~/Downloads
sudo tar -xvf pycharm-community-2019.3.4.tar.gz -C /opt/
sh /opt/pycharm-community-2019.3.4/bin/pycharm.sh

Once the setup begins, you should create a "launcher script" when prompted (make sure to check the "Create a script for opening files and projects from the command line")

At the end of the PyCharm installation process, you will be taken to a welcome screen that looks like this:

PyCharm Welcome
Screen

Click 'Configure' and then open PyCharm's settings, like so:

PyCharm Welcome Screen, with 'Configure->Preferences'
highlighted

In the Preferences window, click 'Project Interpreter', open the dropdown menu, and click 'Show All':

PyCharm Preferences Window, in the 'Project Interpreter' Pane, with
'Show All' highlighted in the dropdown
menu

In the following Window, click the plus icon in the bottom left corner:

PyCharm Interpreter List, with the plus button in the top right 
highlighted

Click 'System Interpreter' in the sidebar. Depending on whether you've installed other versions of Python before, Python 3.9 may already be selected in the dropdown menu. If not, select Python 3.9 and then click 'OK' and 'OK' again:

Adding the system interpreter in
PyCharm

You should now be on a window that looks like this (although the contents of your list might look different):

Interpreter window after selecting system
interpreter

Click 'OK' again to be taken back to the welcome page. You're now ready to test PyCharm!


Testing PyCharm

PyCharm models a program as a 'project', which consists of one or more Python files, as well as any additional resources like images or text files. To get you familiar with working with and running progams in PyCharm, we've provided a sample project, which you can download here. To test out this project, and to gain familiarity with the PyCharm environment, download the sample project Whenever you open projects in PyCharm, open the folder directly containing the files you want to edit as opposed to just the files themselves. Upon opening the project, you should be greeted by a window that looks like this:

Blank PyCharm Window

Click 'Project' in the top left or use the Command + 1 shortcut to open the file explorer, and open intro.py to pull up the editor:

PyCharm Editor

You aren't required to read or understand this code (although you will be able to by the end of the quarter!) but note that this editor is where you'll be writing all your code this quarter. Now, to run your program, click 'Terminal' in the bottom left corner, which will pull up a new terminal pane in your PyCharm window:

PyCharm Terminal

We'll talk more about the terminal later in the quarter, but for now, know that the terminal is how you'll be running your Python programs throughout the quarter. To run your first Python program, type this into the terminal and press enter:

You should see output that looks like this:

First run output

Now, type the following command into the terminal:

For example, if your name is Chris, you'd type python3 intro.py Chris. You can type your full name if you'd prefer. You should now see output like this:

Second run
output

Congratulations! You're now done with the PyCharm setup process.


Frequently Asked Questions

Can I use another version of Python?

Our strong recommendation is to use Python 3.9, which can be installed in parallel with other versions of Python. This is the only version of Python we'll be supporting in this class. You must use at least Python 3.6.

Can I use an editor that isn't PyCharm?

If there's another environment that you're more comfortable with, you may use it, but the course staff will only provide support for issues in PyCharm. You must not modify any configuration files provided in assignment starter code.

When I try to run my code, I'm getting an error saying can't open file intro.py: No such file or directory! What does this mean?

This most often happens when you open the incorrect file or folder in PyCharm. In this case, make sure to open the pycharm_intro folder that directly contains intro.py, rather than intro.py itself or a folder containing pycharm_intro. On Windows computer, you may have a folder called pycharm_intro with another folder inside it called pycharm_intro. Make sure to open the inner folder.

To correct this error, open the 'File' menu and click 'Open'. Then, navigate to the correct pycharm_intro folder and open it.

To verify that you are in the correct folder, type [ls (that's a lowercase 'L')] into your terminal (the same place you type python3 intro.py < YOUR NAME HERE > ). This will show you a list of all the files in that folder, and intro.py should be in this list.

I'm getting a 'No Python Interpreter configured for the project' message when I open a file! What should I do?

This is likely caused by an issue with how you set up the interpreter. To fix this, click 'Configure Python Interpreter', and set up the interpreter by following these steps until the 'Testing Pycharm' section.

I'm on a Mac and I'm getting a message saying The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh. What should I do?

That's just an innocuous message, don't worry about it!

I'm on a Mac and PyCharm won't open! What should I do?

You might be using a slightly older version of MacOS. Try installing this version of PyCharm instead.

Course FAQs will be updated as we receive questions.