Prerequisites - Installation of Python

To take part in this course you need to have installed Python 3, and the python packages: jupyter, numpy, and matplotlib.

Additional things you will need (but will almost certainly already have!)

This section will guide you through how to prepare for the course.

Installing Python

If you have trouble installing python or would prefer more detailed instruction, we recommend you follow the tutorial found here. Otherwise, read on.

Check if Python is already installed

The first step is to install Python if it is not already present on your machine. If you do not know if it is present, try opening a command line/terminal window and executing the command python. If there is no python installed the window will say that the term "python" is not recognized, or some similar message.

You should see this if you have Python installed already.

valid python

Check the version number; yours may not be the same as the one shown here. In the image, it is 3.8.6. If yours reads 3.X.Y then you are good to go, although if X is less than 7 I would recommend upgrading to a more recent version. If it is 2.7.Y then you will need to install Python 3 and should read on. Otherwise, skip to "Installing the Required Packages".

Acquiring Python

Python is approved Ansys software and installers can be found here (get 3.7.4 or 3.8.2, although it is 32 bit only for these versions).

Alternatively, you can download your own installer by opening a browser and heading to this address: https://www.python.org/downloads/release/python-386/ where you will be able to download Python version 3.8.6. This course recommends 3.8 over 3.9 (the latest version) because 3.9 has some known issues with the ipython package which is used by jupyter in this course.

Windows

If you are on Windows then you should download the 64-bit executable installer. Highlighted in this image.

download link

Once downloaded, run the executable and (this part is crucial) tick the "Add Python to PATH" checkbox, before clicking "Install Now".

add to path

If you do not do this you will have to add Python to the PATH manually after installation, through the environment variables.

Mac

Instead of the executable, you should download the dmg. However, installing python is a bit trickier on Mac as it is common for OSX to already have Python 2 installed, though I do not know if this is still the case, and it is necessary to keep that installation. As such, you need to have both installations running alongside each other.

It is recommended that you follow the instructions found here because it is not simple.

Linux

Installing Python on Linux is easier than Mac and can typically be done using sudo apt-get install (depending on your distro), but see here for details on how to do so.

Adding Python to the PATH

If you have not done so already, you must now add Python to the PTH environment variables. This is tricky on Windows but relatively straightforward on Mac/Linux.

Windows

NOTE: The instructions below are fiddly and there are lots of things that can go wrong. As such, I recommend users simply uninstall and reinstall Python, because it is much faster and simpler! If this is not an option, read on.

Bring up the windows launcher and search for "Edit Environment Variables".

launch env vars

Then click on "Environment Variables".

system properties

Now search within the User variables for a variable called "Path". If none exists hit "New", otherwise select the existing one, and click "Edit".

environment variables

Creating a new User Variable

Call your new Variable Path and then "Browse Directory" and proceed to the next section.

new user variable

Editing an existing User Variable

Once you have selected "Path" and hit "Edit", click "Browse..." next and proceed.

edit user variable

Add your Python installation to the Path

Online tutorial available here: https://geek-university.com/python/add-python-to-the-windows-path/ .

Python is typically installed in one of two places, depending on whether it was installed for all users or just for you. If it was installed for all users, it will most likely be in C:\Program Files\Python\Python38\. if you installed it just for yourself (this is the most common eventuality), then it will probably be in your LocalAppData folder. Which is found in C:\Users\YourUserName\AppData\Local\Programs\Python\Python38\ (replace 38 with the version you installed, e.g. 37 for 3.7 or 39 for 3.9).

Beware! AppData is a hidden folder, so you may not immediately see it. In this case, make it visible in your file browser and try again. If you still can't locate the AppData folder, type out the paths in full, as shown in the earlier example, but with your username in place of YourUserName. Similarly, you should add another entry for the Scripts folder one level below this one (as in the screenshot).

Once this is complete, apply your changes by clicking "OK" on each subsequent window. To test if it has worked, open a new command line (an old one will not work) instance and execute the command python. If you see a new python interpreter with a version, as shown earlier, then it has worked! And we are done.

Mac & Linux

The Python path is much more simply edited in Unix and I recommend following these guides to complete your installation:

Installing the Required Packages

Now that we have Python installed, here comes the easy part! This part is identical across all versions of Python and OSs.

Python has a package manager that makes the installation of external packages easy.

All we need to do is run the following commands in the command line:

  • pip install jupyter
  • pip install numpy
  • pip install matplotlib

And that's it!

If the commands run successfully you should see something like this:

pip install

pip install 2

If you have multiple installations of Python installed on your machine and you need to install packages specifically for that installation you should run python -m pip install ... instead, and swap python out for whatever shorthand command you use for the necessary version of Python. py3 and python3 are common ones.

If you have any trouble installing these packages we recommend you read through the official guide here.

Intro & Expectations

This is an introductory video to the course that walks you through the format of the lectures and what to expect. We also introduce Jupyter notebooks which is a popular interactive integrated development environment (IDE) for Python that is used in this course.

Each lesson uses Jupyter notebook and includes lecture contents and corresponding exercises. All other files that are referred to in the Jupyter notebook are also provided.

Lecture