Convert to Package and Module
PyCharm lets you safely restructure your source files by converting a Python module to a Python package and vise versa.
Convert to a Python package
A package typically is a directory that contains modules and initialization code (file __init__.py). A module is a .py source file with Python definitions that can be imported to other modules.
To convert a Python module to a Python package
Select a .py file.
Inspect the project: the package named as the converted module is created; the __init__.py file contains all code from the .py file.
With the package created, you can add more new modules to it, or you can use Move and copy refactorings to derive modules from the initial implementation. You can also modify the __init__.py file to put some initialization code for the package or list all the added modules by using the
Convert to a Python module
You might need to consolidate all modules from a package into a single module.
To convert a Python package to a Python module
Prepare your package for refactoring: move code from all modules in the package to the __init__.py file. See Move and copy refactorings for more details. This is the key action, because only an empty package (a package that has no files but the __init__.py file) can be converted into a module.
Select the package.
Inspect the project: the .py file named as the converted package is created; it contains code from the __init__.py file