BYU logo Computer Science

Activity: Create the cs110 Python environment

There are many versions of Python, and there are many packages you can use.

To help software programmers organize and manage all these versions and packages, Miniconda provides the conda terminal command.

Open your terminal and type:

conda create -n cs110 matplotlib pyqt==5.15.7 pillow pytest

This will create a Python environment named cs110 which we can use for your labs and projects.

After the cs110 environment has been created with the requested packages, we need to activate the environment.

In your terminal type:

conda activate cs110

You should see a (cs110) at the beginning of your terminal prompt after you do this. This indicates that you are now using the cs110 Python environment.

Activity: Run Python in your terminal

Now let’s run Python!

In your terminal type:

conda activate cs110

You should see the (base) at the beginning of your terminal prompt change to (cs110).

Now type:

python

This will start the Python Console. You’ll notice the prompt has changed to >>>.

Now, instead of expecting operating system commands (like conda, cd, or mkdir), your terminal expects python commands.

Try the following (you don’t need to include the >>>; those are included here to make it clear that these are python commands):

>>> 1 + 1
>>> print('hello world!')
>>> print('Hello, my name is <your name> and I am learning how to program')

Activity: Create a PyCharm project

Open PyCharm.

Create a new project.

There are two things you need to tell PyCharm about your project:

  1. Where should it store your files
  2. Which version of Python should it use

First specify the location for your project.

  • Click the Folder icon on the right to browse to your “CS110” folder.
  • In the CS110 folder, create a new folder call “Lab1” (no spaces!)
  • Select “Open” to use the new Lab1 folder

Second, specify the version of Python to use.

  • The first time you use PyCharm, you will need to configure the environment we created earlier (called cs110)
  • Click the triangle next to “Python Interpreter” to expand the interpreter settings
  • Select “Previously configured interpreter”
    • If the cs110 environment is not visible, we need to configure it in PyCharm
      • Select the ... icon on the right
      • Select “Conda Environment” on the left
      • In the “Interpreter” field, select the “cs110” option (the example below shows an environment named jupyter)
      • Select the checkbox “Make available to all projects”
      • Select “OK”
    • Now select the cs110 environment for you project’s Python interpreter.

Unselect the “Create a main.py welcome script”

Select “Create”

Example: creating a new project in PyCharm

Creating a project in PyCharm

Example: configuring a Conda Environment in PyCharm

Configuring a conda environment

Activity: Create a Python Script

In your new Lab1 project, right-click the Lab1 folder in the Project panel on the left side of the window.

Select “New” -> “File” and create a new file named hello.py

Creating a Python script

In hello.py write the following code:

print("Hello world!")

You have now written your first Python script! 💪🏻

Activity: Run Your Python Script

Open your terminal. Activate the cs110 python environment:

conda activate cs110

Then navigate your terminal to the Lab 1 directory:

cd ~/Documents/CS110/Lab1/

You should see a file named hello.py when you type

ls

If so, you’re in the right place. Now type:

python hello.py

This will run your python script.

Try changing the script and running it again. What can you get it to print?

Summary

Things that need to be done just once:

  • Install Miniconda
  • Install PyCharm
  • Create the cs110 Python environment
  • Configure the cs110 environment in PyCharm

Things you should now be comfortable doing:

  • Navigate to a folder in the terminal
  • Run a python script from your terminal
  • Create a new PyCharm project
  • Create a new Python script in PyCharm

It’s very important that you take the time now to set things up and master these skills.

Everything else in this class will build on today’s activities, so make sure you feel comfortable with them!

Grading

ActivityPoints
Create the cs110 environment with conda6
Run Python in your terminal6
Create a PyCharm project6
Create a Python script6
Run a Python script in your terminal6