It’s always a good idea to have a plan before starting a new Python project.
But if you’re not sure how to get everything set up and running, you could end up with “analysis paralysis,” like this newsletter reader:
I’d like to focus more on the “thinking” part of programming and not so much on the “tooling.” I wanted to know what are the right tools to use for the best Python development environment? Trying to code in Python without the right tools can be simply frustrating.
Let’s tackle this question by looking at a typical workflow for developing a Python program.
There are three main steps: setup, development, and sharing. We’ll take a look at how to get through each one, and I’ll link some resources you can use to dive deeper on your own.
STEP 1: SETUP
Before you type a single line of code, it’s important to make sure that your development environment is properly set up.
I suggest starting any new Python project in its own virtual environment. The Virtualenv tool will help you do this. Once it’s established, you’ll use pip to install the desired packages from PyPI and then save those dependencies to a requirements.txt file.
This part can be pretty confusing for newbie coders, so if you’re struggling to grasp these tools, I’ve created a course that will help you figure it out:
After your environment is ready to go, it’s time to start thinking about version control.
This will allow you to easily manage changes to your projects, and restore earlier versions if you’d like.
Setting up a version control system is a vital step in your project’s lifespan, especially if many developers will be making changes to the same codebase.
The most well-known version control system these days is Git, which is often used together with GitHub. This tutorial on Real Python will teach you everything you need to know about the basics of using Git:
STEP 2: DEVELOPMENT
Alright! Your environment is activated, all dependencies are installed, and you’ve initialized a git repo and made your first commit.
It’s time to start writing code!
Most of your programming work will be done in a code editor or IDE. There are dozens out there, from those that support Python (Eclipse, Sublime Text, Atom, Vi/Vim…) to those that are geared towards Pythonistas (PyCharm, Spyder, Thonny).
These editors come with various basic features like syntax highlighting and code formatting, as well as more advanced ones like source control.
It’s up to you to choose which editor to use. Here’s an article to help you get started on your research:
Chances are there will be more than a few bugs in the code that you write.
While you could step through your program line-by-line and debug it manually, this task can quickly grow unwieldy, especially for large-scale applications!
This is when having a dedicated Python debugger can be extremely useful. Luckily, Python has a built-in interactive source code debugger called pdb.
Pdb lets you stop and restart your program’s execution, so that you can easily see how each line of code affects the output. Watching those values change in real time can really help us figure out what we need to do to level-up our programs.
To learn how to get started with pdb, check out this tutorial:
STEP 3: SHARING
Woo-hoo! The source code is complete and you’ve ironed out all the kinks. Now it’s time to share your creation with the world!
If you’ve created a complete application—one that will be used by other devs—you’ll want to make sure your code is well-documented.
(HackerRank’s 2019 survey showed that “badly written documentation” was a huge pet peeve for a lot of developers, so this is more important than ever!)
Pycco is a great tool that makes this task effortless and painless. You’ll be able to generate an HTML file that displays your comments side-by-side with your code. You can learn how to do so in this tutorial:
If instead you wrote a stand-alone script to perform some task, or a series of programs that are part of a larger analysis, then you might want to write up your results in a notebook.
These are documents that contain code snippets, text boxes and visualizations. They can be interactive, web-based applications or statically generated files.
Jupyter is a well-known notebook that supports Python. It’s used by data scientists, analysts, and visualization specialists all around the globe.
To get up and running with Jupyter, check out this tutorial on Real Python:
That brings us to the end of the Python development workflow!
I hope these tools will help you to write and ship more Pythonic code.
— Dan Bader