Set Up PyCharm Project

Your laptop

Your laptop is configured as a development platform, with all the tools you need to do work in this class. Refer to Development Tools under Tools.

Set up file structure

All the work in this class should reside in one folder on your laptop, called comp801. Using bash (WSL or git-bash utility on Windows or terminal on MacOS/Linux)

  • Change directory to your home directory: cd OR cd ~. These commands have the same effect
  • Verify with pwd
  • create comp801 folder: mkdir comp801
  • Verify with ls -al
  • Change directory to comp801: cd comp801
  • Verify with pwd

Organize the work in comp801 into subfolders, labs, homework, practice, project. Thus, create these subfolders with mkdir command.

Set up the virtual environment

Open Root Directory in PyCharm

  • Open PyCharm. Close any opened project to get to the PyCharm Launcher.
  • Use Open project command in the PyCharm Launcher (NOT New!!) in order to locate the comp801 course directory
  • Select comp801 to open it as your PyCharm project root. Do NOT select a subfolder.

PyCharm Terminal

  • Open PyCharm Terminal, it’s a tab on the bottom menu bar.
    • If on Windows, select Ubuntu (corresponding to the Windows Subsystem for Linux), or git-bash from the down arrow that’s next to Terminal: Local menu item on the top bar of the Terminal window.
    • You MUST always have bash or git-bash or Ubunutu in the PyCharm Terminal (NOT PowerShell, if on Windows)
    • If you have conda environment activated in the PyCharm Terminal (the prompt starts with (base), deactivate it:
      • In Windows, run deactivate
      • In MacOS, run source deactivate

PyCharm project root directory and .venv

  • If the virtual environment is set up and active, the Terminal prompt contains (.venv) in it. This is typically the case for MacOS/Linux

  • If (.venv) folder is missing from the project root, or not shown within the prompt, it means that you may not have the virtual environment set up correctly.

    • Open the Python Interpreter pop-up menu from the bottom right corner, where it either says No Interpreter or shows some Python interpreter information.

    • Select Add New Interpreter, select Add Local Interpreter.

    • The Add Python Interpreter screen lists multiple types of environments. Select the first one, Virtualenv Environment.

    • In the Location field make sure you have the absolute path of comp801 directory, ending with /.venv.

      • If it doesn’t end with /.venv, add it. It should look like this:

      /Users/mcs/courses/comp801/.venv

      We prefer to use a dot . for the name of the virtual environment folder, .venv, to indicate that it’s a “hidden” directory. It means that the command ls won’t show it.

  • In PyCharm Terminal check that the Python interpreter you’ll use is from the virtual environment. The command:

    which python

    should show the absolute path of .venv, followed by /bin/python. This is where the local interpreter is located.

    /Users/mcs/courses/comp801/.venv/bin/python

Note Consult with the CAs if you have multiple virtual environments set up in PyCharm. The TAs will show you how to remove the unnecessary ones and have a properly configured comp801 virtual environment.

Python packages

The virtual environment of your project root directory MUST have installed packages that do static analysis of your code, such as pylint and pycodestyle. PyCharm already uses its own code checker. Warnings and errors produced by PyCharm are shown in the PyCharm Problems tab on the status menu bar (at the bottom).

To install packages, In Pycharm Terminal, (git-bash for Windows):

  • Ensure that the virtual environment is active
  • Run package installation using Python pip package installation manager:
    • pip install pylint
    • pip install pycodesthyle
  • Check that the packages have been installed by opening PyCharm Packages tab on the status menu bar (bottom menu)
    • It should list these packages
    • If you see a very long list of packages, it means that the local interpreter for comp801 project root directory is in fact the system-level Python installation.
      • You might also have activated the conda virtual environment in your home directory.