This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

03. Installing the PyCharm IDE

You will install a popular code editor, PyCharm, in your Linux-ish environment.

The most useful tool for a software developer, other than the brain, is an integrated development environment (IDE). You may have used IDEs in your classes, such as IDLE (which is bundled with Python), PyCharm, IntelliJ, Visual Studio, or XCode. IDEs usually have the following capabilities at a minimum:

  • Text editing for writing source code
  • Running the code
  • Debugging (more on this in the future)
  • Browsing files
  • Searching through files
  • Navigating through code structures easily

Most IDEs have many more capabilities. Software developers develop a preference for an IDE based on its capabilities, its ease-of-use, and the programming languages it supports.

In this class, we will use PyCharm, an IDE published by JetBrains. It has many handy features to support Python programming.

PyCharm works on Windows, Mac, and graphical Linux-based operating systems. If you are using Windows, we want to run it from our Linux environment

Choose the section corresponding to your Linux environment for instructions on installing PyCharm.

1 - for WSL

Instructions for installing PyCharm to work with the Windows Subsystem for Linux

This lab is for those who are on Windows and have set up the Windows Subsystem for Linux (WSL) following Option 1 from the Installing a *nix operating system lab.

Installation

  1. You must request a free PyCharm Professional license. Sign up using your @uncw.edu email address.
  2. Download and install PyCharm for Windows. You must have Pycharm Professional, not the Community edition.
  3. Complete the install process. I recommend the options below, but they are not required:
    Pycharm installation options on windows

Setup

  1. Run PyCharm after installation is complete.
  2. You should see a prompt to activate the license. Select “Activate License” then “Log In to JetBrains Account”.
    PyCharm license activation prompt
    Pycharm activation options
  3. Complete the login process using the Jetbrains website.
  4. You should now see a “Welcome to PyCharm” screen. Select “WSL” in the left pane, then click “New Project” in the main pane.
    Selecting WSL from the PyCharm home page
  5. You WSL instance you created should already be selected. Click “Next”.
    Choosing a WSL instance.
  6. PyCharm will process for a minute then present a “Choose IDE and Project” screen. Leave the “IDE Version” as-is. Click the ... next to the “Project directory” selector.
    IDE and Project configuration options.
  7. We are now going to create a directory in Ubuntu to keep all your class projects. We will also create a new test subdirectory in that directory.
    1. In the pop-up, expand the directories to select \\wsl.localhost\Ubuntu\home\<your_username>. Left click to select the directory.
    2. Then click the “New Directory” button at the top.
    3. Then enter seng-201 in the pop-up name box.
      Creating the 201 folder
    4. Now select the seng-201 folder and click the “New Folder” button again. Enter pycharm-test in the box.
      Creating a test project.
    5. Finally, select the pycharm-test folder and click “OK”.
  8. You will be back on the “Select IDE and Project” page. It should look like below. Click the blue “Download IDE and Connect” button.
    Accept project settings.
  9. PyCharm will take several minutes to download and configure necessary software to talk to your Ubuntu instance. After it completes, you will be shown a user agreement. Accept it.
    Download progress.
    License agreement.
  10. Finally, you should see the PyCharm IDE editor window. Click the Play button at the top to see the Python program run. You are done with the setup.
    PyCharm running on WSL

You may see some Windows Firewall pop-ups. It is okay to allow them.

Configure the Ubuntu CLI

Finally, we are going to make it so you can open PyCharm from the Ubuntu CLI. This will be very convenient later.

  1. First, close PyCharm.
  2. Open an Ubuntu Terminal as described in the previous lab.
  3. Run the following command, which will create an alias to run PyCharm from the command line:
bash

printf "pycharm() { \"/mnt/c/Program Files/JetBrains/PyCharm 2024.3.1.1/bin/pycharm64.exe\" \"\$@\" > /dev/null 2>&1 & }\n" >> ~/.bashrc && source ~/.bashrc

Test drive

Let’s open PyCharm from the Ubuntu CLI and do somet light editing.

  1. Run the following commands from the Ubuntu terminal:

    bash
    
    cd       # make sure in your home directory
    cd seng-201
    cd pycharm-test  # change to test directory
    pycharm .   # launch PyCharm in the current directory
    

  2. PyCharm should open after a moment. You may see a prompt to “Trust the directory…”. Do that. You may need to click on the Explorer icon in PyCharm to see your files:

  3. Go back to your Ubuntu terminal and make sure you are in the pycharm-test directory.

  4. Type the command touch hello.py to create an empty Python file.

  5. Go back to PyCharm. You should see the file hello.py in the directory here. Click on it and it will open an empty editor pane.

  6. In the code editor, type print("Hello World").

  7. Go back to the Ubuntu Terminal and type cat hello.py. You should see the code.

Next

So you now have PyCharm successfully editing files and interacting with directories inside Ubuntu.

You are now ready to code! Move on to the PyCharm basics lab.

2 - for VirtualBox

Instructions for installing PyCharm on Ubuntu running in VirtualBox

This lab is for those who are on Windows and are running Ubuntu inside VirtualBox using Option 2 for Windows from the Installing a *nix operating system lab.

Installation

  1. You must request a free PyCharm Professional license. Sign up using your @uncw.edu email address.
  2. Open VirtualBox and start up your Ubuntu virtual machine (VM). Sign in to Ubuntu.
    • You may want to go full screen. Do this by selecting View -> Full Screen.
    • If the Full Screen is small, right-click on the Desktop -> Display Settings then change the Resolution to something larger, probably 1920x1080.
    • You exit full screen by hitting Right CTRL+F
  3. You should open this page in Firefox launched within Ubuntu for easy copy-and-paste.
  4. Open a Terminal as described in the Launching a Terminal lab.
  5. Copy and paste in the following commands. You will need to enter your password.
    bash
    
    BUILD=2.5.2.35332
    sudo apt install libfuse2 libxi6 libxrender1 libxtst6 mesa-utils libfontconfig libgtk-3-bin
    wget https://download.jetbrains.com/toolbox/jetbrains-toolbox-$BUILD.tar.gz
    tar -xzf jetbrains-toolbox-$BUILD.tar.gz && cd jetbrains-toolbox-$BUILD && ./jetbrains-toolbox
    
  6. The commands will take a few minutes to run. You should see a JetBrains Toolbox window popup when done. Agree to the JetBrains User Agreement and click Start (you may need to scroll down in the popup).
    JetBrains Toolsbox start screen
  7. Scroll down to PyCharm Professional and click “Install”. PyCharm will download.
    Select and install pycharm

Running PyCharm

  1. Click on PyCharm Professional in the JetBrains Toolbox.

  2. PyCharm will launch and show license prompts. Select “Activate License” then “Log In to JetBrains Account”.

    PyCharm license activation prompt
    Pycharm activation options

  3. Complete the activation in the web browser. Then go back to PyCharm. You should see that you are signed in. Click “Done” and you should see the main PyCharm launch page.

    PyCharm launch screen

  4. The Ubuntu “Dash Bar” is on the far left of the screen. Right-click on PyCharm and select “Pin to Dash” to easily launch it.

    Pin PyCharm to dash bar

  5. Finally, run the following command in the Ubuntu Terminal, which will create an alias to run PyCharm from the command line:

    bash
    
    printf "pycharm() { nohup ~/.local/share/JetBrains/Toolbox/apps/pycharm-professional/bin/pycharm.sh \"\$@\" >/dev/null 2>&1 & }\n" >> ~/.bashrc && source ~/.bashrc
    

You should now be good to go to develop Python code in Ubuntu.

Test drive

We are going to create a sample project directory in Ubuntu, then open PyCharm and edit files in that Linux directory. A video follows the steps.

  1. Start a new Terminal in Ubuntu.
  2. Run the following in the Terminal:
    bash
    
    cd       # make sure in your home directory
    mkdir seng-201   # This directory will hold all our code for the course
    cd seng-201      # change to the new directory
    mkdir pycharm-test  # Make a new subdirectory for a test project.
    cd pycharm-test     # change into the subdirectory
    pycharm .   # launch PyCharm in the current directory
    
    The pycharm command launches the PyCharm program. The command pycharm . says launch Pycharm and have it open the current working directory. The symbol . always means the working directory. Sometimes it will be necessary to explicitly tell the CLI we are referring to the working directory; more on those situations as they arise.
  3. A PyCharm window will open after a moment.
  4. You may be asked if you “trust the authors of the files in this folder”. Click the checkbox and then pick “Yes, I trust the authors.”

Here is the process in a video:

Creating a new file

Let’s create a file in the Terminal in our project directory. We should see it immediately in PyCharm.

  1. Go back to your Ubuntu terminal and make sure you are in the pycharm-test directory.
  2. Type the command touch hello.py to create an empty Python file.
  3. Go back to PyCharm. You should see the file hello.py in the directory here. Click on it and it will open an empty editor pane.
  4. In the code editor, type print("Hello World").
  5. Go back to the Ubuntu Terminal and type cat hello.py. You should see the code.

Next

So you now have PyCharm successfully editing files and interacting with directories inside Ubuntu.

You are now ready to code! Move on to PyCharm Basics lab.

3 - for Mac

Instructions for installing PyCharm on Mac

This lab is for those who are installing PyCharm on Mac machines.

Installation

  1. You must request a free PyCharm Professional license. Sign up using your @uncw.edu email address.
  2. Download PyCharm Professional for Mac .dmg file.
  3. Locate the downloaded .dmg file and click to open. Drag PyCharm into the Applications folder.

Setup

  1. Open your Finder, select Applications, then PyCharm.
  2. You may wish to pin PyCharm to your dock after launching.
  3. You should see a prompt to activate the license. Select “Activate License” then “Log In to JetBrains Account”.
    PyCharm license activation prompt
    Pycharm activation options
  4. Complete the login process using the Jetbrains website.

Enable launching PyCharm from the Terminal

  1. Open the Mac Terminal application as described in the Launching a Terminal lab.
  2. In the Terminal, type the command
    
    sudo nano /usr/local/bin/pycharm
    
  3. Enter your password when prompted.
  4. You will now see the Nano text editor in your terminal. Type or paste in the following:
    
    #!/bin/sh
    
    open -na "PyCharm.app" --args "$@"
    
    Creating a pycharm launch script using nano
  5. Hit Control+O to save, then Enter to accept the filename.
  6. Hit Control+X to exit the text editor.
  7. Run the following command in the Terminal:
    
    sudo chmod +x /usr/local/bin/pycharm
    

You will now be able to type pycharm . in the Terminal to open PyCharm to edit the current directory’s contents.

Test drive

We are going to create a sample project directory using the Terminal, then open PyCharm and edit files in that directory. A video follows the steps.

  1. Open the Terminal application.
  2. Run the following in the Terminal:
    
    cd       # make sure in your home directory
    mkdir seng-201   # This directory will hold all our code for the course
    cd seng-201      # change to the new directory
    mkdir pycharm-test  # Make a new subdirectory for a test project.
    cd pycharm-test     # change into the subdirectory
    pycharm .   # launch PyCharm in the current directory
    
    The pycharm command launches the PyCharm program. The command pycharm . says launch Pycharm and have it open the current working directory. The symbol . always means the working directory. Sometimes it will be necessary to explicitly tell the CLI we are referring to the working directory; more on those situations as they arise.
  3. A PyCharm window will open after a moment.
  4. You may be asked if you “trust the authors of the files in this folder”. Click the checkbox and then pick “Yes, I trust the authors.”

Here is the process in a video:

Creating a new file

Let’s create a file in the Terminal in our project directory. We should see it immediately in PyCharm.

  1. Go back to your Terminal and make sure you are in the pycharm-test directory.
  2. Type the command touch hello.py to create an empty Python file.
  3. Go back to PyCharm. You should see the file hello.py in the directory here. Click on it and it will open an empty editor pane.
  4. In the code editor, type print("Hello World").
  5. Go back to the Ubuntu Terminal and type cat hello.py. You should see the code.

Next

So you now have PyCharm successfully editing files and interacting with directories on Mac.

You are now ready to code! Move on to PyCharm Basics lab.