If you’d like some help with managing multiple Python versions on your machine, then check out Start Managing Multiple Python Versions With pyenv.
Scaffold the Project Structure
00:00 Scaffold the Project Structure. The first step is to use your favorite code editor or a cloud-based IDE to create a new Python project while specifying an isolated virtual environment for the dependencies needed.
00:14 The minimum interpreter version required for this project is Python 3.10 due to a few syntactic constructs that you’ll be using. If you can, consider switching to a more recent release for better performance and other improvements.
If you want to know about managing multiple Python versions on your computer, then take a look at this Real Python course. Once you have the project set up in your editor, scaffold the initial folder structure with these two nested Python packages, both of which should be empty at this point. By placing the project’s root package under the
src/ subfolder, you follow the so-called src layout convention for organizing files in a project.
01:07 You can read about their differences in the official Python Packaging User Guide. In a nutshell, the src layout is preferred for larger projects because it allows you to better separate the project code from other files, such as tests.
While the project’s name is
maze-solver with a hyphen, you name the corresponding Python package using an underscore (
_) to form a valid Python identifier, which follows the same rules as variable names.
01:38 The rules for naming a Python project, or a distribution package in slightly more technical terms, are more liberal. If you’re curious enough, you can check out PEP 508 to find the regular expression that validates these names.
02:14 is a pretty standard configuration and a good starting point for most Python projects and libraries. Note that you don’t have to explicitly state the folder layout you are using because build tools such as setuptools will automatically find the Python source code. If you’re planning to publish your package on PyPI, then you should pick a globally unique name that won’t conflict with an existing Python distribution package. Other than this, you have a fair amount of freedom in choosing your project name.
02:46 It’s good practice to work in a Python virtual environment when you’re working with third-party packages or installing your own. So, on-screen you’ll see one being created on macOS with the commands that will also work on Linux.
During the development of a src-layout project, it’s advisable to use the
--editable flag or its
-e alias to ensure that any changes you make to your code are immediately reflected in the virtual environment. Otherwise, you’d need to manually reinstall the package each time you edit the code.
Become a Member to join the conversation.