Setting up the environment

Setting up a virtual environment is recommended when working locally.

We can use conda create from the Anaconda software for this. For this project, we’ll create an environment called educative that will use Python version 3.10.

Any name can be used for the environment.

conda create --name educative python==3.10

Instead of using conda, we can also use virtualenv.

To activate the conda environment, write the following:

conda activate educative

When working locally, it may also be handy to install Jupyter Notebook. This will provide us with a useful user interface for interactive programming.

Installing the python-barcode library

Next, it is time to install the required Python library for writing barcodes.

The recommended library is called python-barcode, which we’ll use in this course. As the library is not available via conda install, we will use pip install instead to install it.

It can be installed as follows:

pip install python-barcode

In this case, the standard output will be in the SVG image file format.

Given that we may want to output the barcodes in other image formats as well, we can use the following instead:

pip install python-barcode[images]

This will install both the python-barcode and the Pillow image library in the educative environment. This will allow us to also use image formats like PNG or JPG.

Get hands-on with 1400+ tech skills courses.