PyCharm 2016.3 Help

Convert to Python Package/Module

In this section:

Overview

These two refactorings enable easy conversion between a Python module and package.

Both refactorings are performed silently.

Converting a file to a module

To convert a file to a package, follow these steps

  1. In the Project tool window, select the desired file.
  2. On the Refactor menu, choose Convert to Python Package.

The new package named by the original file is created. So doing, the content of the original file moves to the file with the name __init__.py.

Example

BeforeAfter
/help/img/idea/py_convert_to_package.png
/help/img/idea/py_convert_to_package_result.png

Converting a package to a module

To convert a package to a module, follow these steps

  1. In the Project tool window, select the desired Python package (marked as /help/img/idea/package.png), or the nested file __init__.py.
  2. On the Refactor menu, choose Convert to Python Module.

Example

BeforeAfter
/help/img/idea/py_convert_to_module.png
/help/img/idea/py_convert_to_module_result.png

See Also

Last modified: 23 November 2016