PyCharm does this automatically now by use of Code -> Optimize Imports. It also sorts them into groups per PEP 8.

See https://www.jetbrains.com/help/pycharm/optimizing-imports.html for details.

Answer from Quark on Stack Overflow
🌐
JetBrains
jetbrains.com › help › pycharm › creating-and-optimizing-imports.html
Auto import | PyCharm Documentation
1 month ago - To optimize imports in a file, you can also press Ctrl+Alt+Shift+L, select Optimize imports, and click Run. If your project is under version control, you can configure PyCharm to optimize imports in modified files before committing them to VCS.
🌐
JetBrains
blog.jetbrains.com › pycharm › 2018 › 11 › let-pycharm-do-your-import-janitorial-work
Let PyCharm Do Your Import Janitorial Work | The PyCharm Blog
January 15, 2024 - PyCharm can optimize imports in a single file. But you can also optimize imports across the entire project. Select the folder at your project root, then trigger Optimize Imports (from the menu, the shortcut, or Find Action.)
Discussions

How do I optimize imports in Python using PyCharm? - Stack Overflow
Wanting to expand my horizons I decided to pick up programming and I've read that python is very beginner-friendly, knowing this I downloaded the program in addition to the PyCharm text editor and More on stackoverflow.com
🌐 stackoverflow.com
How to stop Pycharm adding imports to my code automatically ?
Have you checked the settings? It should not add imports automatically. Or do you use any PyCharm plugins that do that extra stuff? Just disable features you don't like or need. More on reddit.com
🌐 r/pycharm
7
14
December 3, 2024
pycharm - Is there a shortcut to merge import statements - Stack Overflow
Is there any other short cut available to do this in Pycharm? just curious. ... Now in the imports tab of Python Code Style, check the box saying Join "from" imports with the same source as shown in the above screenshot, now whenever you run Optimize imports by running Ctrl+Alt+O or code > ... More on stackoverflow.com
🌐 stackoverflow.com
Optimize Imports not completely working correctly...
There is nothing wrong here. csv/json/datetime/etc are python builtins and thus come first. Django and tqdm are external libraries and come second. FInally your own source code imports. More on reddit.com
🌐 r/pycharm
1
3
July 2, 2022
🌐
JetBrains
jetbrains.com › pycharm › guide › tips › optimize-imports
Optimize Imports - PyCharm Guide
February 17, 2023 - With the Optimize Imports action ⌃⌥O (macOS) / Ctrl+Alt+O (Windows/Linux), you can quickly remove any unused imports, merge imports from the same module, and optionally sort the import statements.
🌐
Quora
quora.com › What-does-optimize-imports-mean-on-PyCharm
What does 'optimize imports' mean on PyCharm? - Quora
Answer (1 of 2): it means that if you are doing this : [code]from math import cos from math import sin from math import sqrt from math import factorial [/code]and you optimise imports it will convert that to : [code]from math import cos, sin, sqrt, factorial [/code]further more it will remove a...
🌐
YouTube
youtube.com › watch
How to optimize imports in PyCharm - YouTube
In this very short video you will learn how to automate the organizing and cleaning up of your Python imports with Optimize Imports.00:00 - Start00:12 - Show...
Published   May 29, 2020
Find elsewhere
🌐
JetBrains
jetbrains.com › guide › python › tips › generate-imports-while-typing
Generate Imports While Typing - JetBrains Guide
February 17, 2023 - While typing, press ⌃␣ (macOS) / Ctrl+Space (Windows/Linux) to tell PyCharm to autocomplete on symbols from modules. When you select the completion target, PyCharm will also generate the import -- in the right place, merging it with an existing ...
🌐
JetBrains
jetbrains.com › pycharm › guide › tips › optimize-imports
Clean Up Messy Imports With Optimize Imports - JetBrains Guide
February 17, 2023 - With the Optimize Imports action ⌃⌥O (macOS) / Ctrl+Alt+O (Windows/Linux), you can quickly remove any unused imports, merge imports from the same module, and optionally sort the import statements.
🌐
Reddit
reddit.com › r/pycharm › optimize imports not completely working correctly...
r/pycharm on Reddit: Optimize Imports not completely working correctly...
July 2, 2022 -

Hi - I'm using the optimize imports functionality and it mostly works but it misses some libraries. The ones I've seen so far are tqdm and dateutil. Here's what it looks like after I optimize the imports. Any idea why this is happening / how to fix it? Note that from tqdm import tqdm is grouped with the django imports:

import csv
import json
from datetime import datetime
from decimal import Decimal
from itertools import chain

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.cache import cache
from django.db.models import (Avg, Count, ExpressionWrapper, F, FloatField, Q, Sum, fields)
from django.http import HttpResponse, StreamingHttpResponse
from django.shortcuts import render
from tqdm import tqdm

from common.dashboard_util import (construct_cache_name, correct_start_dates, get_all_drilldown_objects,
                               get_dates_for_columns, get_drilldown_object_id, get_landing_page_variables,
                               get_lookup_values_by_time_period, get_master_query_from_slug, get_time_to_find)
from core.util import (get_parent_object_from_slug)
from eclose.models import eCloseDefaultFilter
from loan.models import Loan
🌐
JetBrains
jetbrains.com › help › pycharm › reformat-and-rearrange-code.html
Reformat and rearrange code | PyCharm Documentation
January 6, 2026 - Optimize imports: select this option if you want to remove unused imports, add missing ones, or organize import statements.
🌐
Stack Overflow
stackoverflow.com › questions › 68225630 › auto-formatting-imports-in-pycharm-professional-edition
python - Auto-formatting imports in PyCharm Professional Edition - Stack Overflow
And when I'm doing a commit stage via (Alt+0) PyCharm's commit interface it autoformats these imports to this: Copyfrom here import this from here1 import this1 from here2 import this2 ... I'm not really looking for a style guide but rather for a reason isort auto-formats my imports, sometimes it will even format files I didn't touch or opened. ... I think it's the first option "Sort imported names in "from" imports" Do you have optimize imports enabled in the IDE?
🌐
JetBrains
jetbrains.com › guide › python › tips › one-import-per-line
One Import Per Line Preference - JetBrains Guide
February 17, 2023 - Lots of code can mean lots of imports. Python is pretty picky about style, and so are you, which can mean lots of tedious manual gardening of your imports. PyCharm's Optimize Imports acts as your import janitor and it has settings which let you specify some options on style import.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 206592765-Marking-an-import-to-prevent-deleting-it-with-optimize-imports
Marking an import to prevent deleting it with "optimize imports" – IDEs Support (IntelliJ Platform) | JetBrains
April 19, 2012 - In django I often use something likein models.py or urls.py:import signalsI don't use singlas later in code, this is just to run signals.py code with django. PyCharm marks this import as unused, an...
🌐
Medium
johndcyber.com › pycharm-keyboard-shortcuts-afa264734004
Pycharm Keyboard Shortcuts… | by John D Cyber | Medium
March 4, 2024 - One of the most well-known IDEs for Python programming is PyCharm, created by JetBrains. It provides a wide variety of keyboard shortcuts to speed up the coding process. Here are several keyboard shortcuts that may come in handy on Windows, Linux, and macOS: ... Join Medium for free to get updates from this writer. ... This is the official documentation and it provides a comprehensive list of keyboard shortcuts for various operating systems, along with tips and tricks to optimize your workflow using shortcuts.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 115000035164-Unconfigurable-Auto-Remove-of-Unused-Python-Imports
Unconfigurable Auto Remove of Unused Python Imports – IDEs Support (IntelliJ Platform) | JetBrains
January 16, 2017 - It would be nice to to add a setting ... Style -> Python -> Imports that allows you to keep "unused" imports around instead of deleting them. Any guidance on how to submit such a feature request? ... Sure, feel free to create a dedicated issue on YouTrack, but I doubt it makes a lot of sense since deleting unused imports is basically the main purpose of "Optimize Imports". As for removal of commented out import statements, it's a known pesky problem that will be fixed in PyCharm ...