Register to get access to free programming courses with interactive exercises

Accessibily for working with Python Python: Setting up the environment

A programming language is useless without a suitable interpreter or compiler.

But programs not only have to run, they also have to be delivered to the user. And the programs are rarely ready to go, so we need to update them after the installation. And they need to be developed further, sometimes for several years.

Sometimes, situations arise where you need to update third-party libraries and sometimes the compiler or interpreter itself. Several tools have appeared and evolved in Python to solve the above issues. We will discuss some of them below. In this lesson, we will talk about the importance of choosing your tools.

Most tools have good documentation, and we won't repeat it here. The lesson's purpose is to give you a general idea of what's available and to empower you to choose which tool you want from those available.

But first, let's get acquainted with a new concept — lock files.

What are lock files

When developing any library, the author should specify the versions of third-party packages required to make his code work.

Usually, the versioning is not rigid. Instead, programmers specify a range of versions that do not compromise compatibility between different parts.

But things don't go as planned sometimes:

  • People may use a version range that is too wide
  • Semantic versioning may not work properly
  • There may be a bug in some package versions

In such cases, the project only works with a combination of different package versions and not with all of them, as may have been intended.

A lock file can help with this problem. It lists packages with their versions currently suitable for the project. Programmers use lock files in one form or another by most package managers for different programming languages.

Interpreter version control — pyenv

Even while you're learning, you should have an up-to-date interpreter version. Python is suitable for automation needs, so it's often available in the package directories of different operating systems. As a rule, packages only contain CPython. But other implementations and versions of Python interpreters are helpful in different situations.

Library authors often have to maintain multiple versions of Python and check whether new changes in code affect performance in different versions of Python.

Thus, you can install several different implementations of Python on one computer, each with several variants. You can control all this with pyenv.

The pipenv tool

The pipenv program takes over:

  • Package management via pip
  • Creating virtual environments with venv
  • Working with dependencies
  • Control over versioning and updating
  • Building dependency graphs
  • Reproducing assembly with lock files

It is a powerful tool, but there is one issue; you have to use distutils and Setuptools to describe how to build a package with a project. It may be difficult for newcomers to master this aspect, but other than that, it's convenient to use this program.

Poetry

In our courses and projects, we recommend using Poetry. It's also with Poetry that our python package boilerplate is designed. What kind of tool is it?

Overall Poetry — is a relatively new project that simplifies development in Python. It solves all the same problems as pipenv but also takes care of package assembly. Moreover, when you use Poetry, you don't need to delve deep into distutils or Setuptools.

Poetry's documentation is concise and clear. It describes the recommended structure of directories in a typical project, the use of alternative indexes, and many other aspects.

IPython

The Python REPL is pretty simple, and most importantly, it's always available. It is hard to work with for multi-line code and large programs.

The good news is that the REPL in Python is modular. There are several improved versions of it. The most popular of which is IPython.

IPython has:

  • Syntax highlighting
  • Auto-add modules for importing and defining modules
  • Tips for function arguments and displaying documentation
  • Much more

Most data analysts spend most of their time in IPython because it is powerful and easy to use.

Other tools

Over the decades, a large number of tools have emerged around Python. It is a common courtesy to document your code thoroughly when we speak about programming in Python. So, you can learn almost any tool on your own. You can always go to the PyPI website and browse the list of topics. You'll find projects that can make your life easier and development more convenient.


Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

Bookmate
Health Samurai
Dualboot
ABBYY
Suggested learning programs
profession
new
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.