How To Create Your Own Avatar Using Python ?

- By Pratyush Mishra

How To Create Your Own Avatar Using Python ?
Listen to this article

Hi everyone👋 , In this article, we will discuss how to create a custom avatar using Python. In order to perform this task. You don’t have to create it yourself on software or download it from some website, but a few lines of code will help you to generate an avatar of your choice.You can refer to my YouTube video to see a working tutorial for better understanding and a step-by-step guide of the same.

We will be using the py-avataaars package from which we will be creating those beautiful avatars.

The basic syntax of this module is:

from py_avataaars import PyAvataaar

avatar = PyAvataaar()

Here the PyAvataaar Class is in the which is responsible for a number of functionalities, out of which the major one is setting the parameters of the avatar for eg: change in skin color, outfit, eyes, hairs, hair colors, moods etc.

So, let’s begin…

Step 1 : Installation of some packages.

  • First type pip install py-avataaars in your terminal to install the avatars package (Check: for more information)

  • Then download and install this gtk file from here gtk3-runtime-3.24.24-2021-01-30-ts-win64.exe. Your antivirus will try to block it, but you should allow it to download for the code to run properly, trust me guys it’s a non-harmful file (Check: for more information)

Step 2 : Writing the python program.

  • First, we will try to generate the default avatar by writing this code and see if this works properly or not Python3
# importing the require package
from py_avataaars import PyAvataaar  

# assigning various parameters to our avatar
avatar = PyAvataaar()

# rendering the avatar in png format

Output :


The above program will generate the AVATAR_1.png file in the folder where you’ve kept this python program. Once the above program is running properly, then we will generate the avatars according to our needs with by using PyAvataaar() method.

Syntax :

PyAvataaar(style, skin_color, hair_color, facial_hair_type, top_type, mouth_type, eye_type, eyebrow_type, nose_type, accessories_type, clothe_type, clothe_graphic_type)

Implementation :

# Python program to create custom avatars

# importing the require package
import py_avataaars as pa  

# assigning various parameters to our avatar
avatar = pa.PyAvataaar(style=pa.AvatarStyle.CIRCLE,

# rendering the avatar in png format

Output :


You can always change the parameters of the avatar accordingly by pressing the Ctrl button and hovering over the py_avataaars line, which will turn it blue, and then you can click on it to see file, where you can find all the parameters, each written in a different class.

Alright, guys! I hope this article was helpful for you if it is the leave your comments below. I will meet you in another article until then KEEP CODING🤗.

Share this