Categories
Uncategorized

AI Tutorial: Python (PyCharm) Setup

I’ve primarily written this section for people who are completely new to Python and programming. If you comfortable with setting up a Python environment, you can skip to Part 2.

For everyone else, first download and install the newest versions of Python and PyCharm. This should be straightforward, but if you have any issues, please consult their websites. I should note that PyCharm is just one of the many IDEs that you could use to facilitate your Python code, but it is the one that I first became accustomed to when I was learning Python, so I’ve chosen it for this tutorial as well.

Once they are both installed, open PyCharm and start a new project. Name it whatever you would like, as long as you can remember it and find it later. I will name mine “Tutorials”. Click File > New, then select Python File. In the “New Python file” box, type the name of the file (in this case, Image_Process). This will create a new file in your project folder. In this case, it is C:\Users\Daniel\PycharmProjects\Tutorials\Image_Process.py.

Now, we need to set up our python environment. Go to File > Settings and you should see the following window, though yours may have less packages listed. First, ensure that your Project Interpreter (shown with a blue box) is correct. This Interpreter indicates the version of Python you are using, as well as the packages that you have installed for a particular environment. I have just chosen the Python 3.8 system interpreter, which includes all of the packages installed locally on the system. Another popular option would be to create a different virtual environment for each project, which ensures that any projects that require different versions of a package, or different versions of Python, can remain separate and will not interfere with one another. To do this, you need to click the “Settings” wheel on the right side of the blue box, select “Add…”, then the “VirtualEnv Environment” option. However, this is not the topic of this tutorial.

Next, we need to actually install the necessary packages within the Project Interpreter. Any time you get a ModuleNotFoundError when running your code, it indicates that you have not installed a package that you are attempting to import to your program, so this is where you will need to come in order to install those packages into your current environment. Even if you have installed this package elsewhere, if it isn’t present in the environment you are currently using, it will not be accepted in the program. To install a package, click the “+” button indicated by the red box, and search for the package. For the ImageProcess tutorial, you’ll need to import “opencv-python” and “numpy” (which may be installed automatically during installation of opencv-python). OpenCV is one of the most popular libraries used for image processing. Originally written in C/C++, it has been adapted to be usable in python. NumPy, on the other hand, is a package for handling numbers and numerical structures such as arrays and matrices.

Once you have the necessary packages installed, we are ready to start coding.