ImportError: cannot import name 'executor' from 'aiogram': how to fix it
ImportError: cannot import name 'executor' from 'aiogram' means code written for aiogram 2 is running on aiogram 3, which removed executor entirely. Rewrite the start for aiogram 3: Dispatcher() without the bot, handlers registered with @dp.message, and await dp.start_polling(bot) inside asyncio.run(main()). Pinning aiogram below 3 only postpones that rewrite.
By Livops team, the people who build and run LivopsUpdated
The bot stops at startup with this at the end of the traceback:
ImportError: cannot import name 'executor' from 'aiogram' (/home/me/bot/.venv/lib/python3.12/site-packages/aiogram/__init__.py)
The code was written for aiogram 2, and the aiogram that is installed is 3.x. This page explains what aiogram 3 removed, shows the same bot before and after the rewrite, lists the errors that come right after this one, and explains why pinning aiogram 2 is only a stopgap.
What does the error mean?
In aiogram 2 a bot was started by a helper called executor: executor.start_polling(dp)[6]. aiogram 3 removed it entirely; the Dispatcher now starts polling or handles webhooks itself[1]. The package no longer exports executor at all[2], so from aiogram import executor fails, and so does from aiogram.utils import executor.
The same release changed two more things that every aiogram 2 bot uses[1]:
- The Dispatcher no longer takes the bot.
Dispatcher(bot)becomesDispatcher(), and the bot is passed only when polling starts or a webhook update is handled. That is what lets one dispatcher serve several bots. - The
_handlersuffix is gone from every decorator:@dp.message_handler()becomes@dp.message(), and@dp.callback_query_handler()becomes@dp.callback_query().
The executor is usually the first line Python trips on, because it sits in the first import. Fix only that and the next error is waiting a few lines further down.
Which aiogram is installed?
Run this with the same Python the bot runs with:
pip show aiogram
python -c "import aiogram; print(aiogram.__version__)"
Version 3.0.0 and later have no executor. aiogram 3.0.0 was released in September 2023[8], so a requirements.txt that says only aiogram, or aiogram>=2.20, now installs aiogram 3 on every fresh install, while an old laptop or server still has 2.x. That is why the same code works in one place and fails in another.
The fix: rewrite the start for aiogram 3
A typical aiogram 2 bot, close to the project’s own 2.x example[6]. This is the code that fails on aiogram 3:
import os
from aiogram import Bot, Dispatcher, executor, types
bot = Bot(token=os.environ["BOT_TOKEN"])
dp = Dispatcher(bot)
@dp.message_handler(commands=["start"])
async def start(message: types.Message):
await message.answer("Hi!")
@dp.message_handler()
async def echo(message: types.Message):
await message.answer(message.text)
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
The same bot for aiogram 3, following the 3.x example[5]:
import asyncio
import logging
import os
from aiogram import Bot, Dispatcher, F
from aiogram.filters import CommandStart
from aiogram.types import Message
dp = Dispatcher()
@dp.message(CommandStart())
async def start(message: Message) -> None:
await message.answer("Hi!")
@dp.message(F.text)
async def echo(message: Message) -> None:
await message.answer(message.text)
async def main() -> None:
bot = Bot(token=os.environ["BOT_TOKEN"])
# aiogram 3 has no skip_updates=True: drop the queued updates yourself
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main())
What changed, line by line:
- No executor.
asyncio.run(main())starts the event loop once, andawait dp.start_polling(bot)runs inside it[5]. Do not callasyncio.runagain anywhere inside the bot; why is in This event loop is already running. Dispatcher()without the bot, which goes tostart_polling(bot)instead[1].@dp.message(...)instead of@dp.message_handler(...), with filters as objects:CommandStart()orCommand("start")instead ofcommands=["start"][1].F.texton the echo handler. In aiogram 2 a handler without arguments implicitly received only text messages outside any FSM state; in aiogram 3 it receives every content type in every state[1]. WithoutF.text, the first sticker reachesmessage.textasNone.skip_updates=Trueis gone. To skip what queued up while the bot was down, calldelete_webhook(drop_pending_updates=True)before polling[1].
Handlers in several files: Router
The Dispatcher is itself the root Router[4]. When handlers live in their own modules, give each module a Router and include it into the Dispatcher:
# handlers.py
from aiogram import F, Router
from aiogram.types import Message
router = Router()
@router.message(F.text == "ping")
async def ping(message: Message) -> None:
await message.answer("pong")
# bot.py
import asyncio
import os
from aiogram import Bot, Dispatcher
from handlers import router
async def main() -> None:
bot = Bot(token=os.environ["BOT_TOKEN"])
dp = Dispatcher()
dp.include_router(router)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
Old line, new line
| aiogram 2 | aiogram 3 |
|---|---|
executor.start_polling(dp) |
await dp.start_polling(bot) inside asyncio.run(main()) |
Dispatcher(bot) |
Dispatcher() |
@dp.message_handler(...), @dp.callback_query_handler(...) |
@dp.message(...), @dp.callback_query(...) |
commands=["start"] |
Command("start") from aiogram.filters |
content_types=ContentType.PHOTO |
F.photo |
text="hello" |
F.text == "hello" |
message.get_args() |
command: CommandObject in the handler, then command.args |
Bot(token, parse_mode="HTML") |
Bot(token, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) |
aiogram.contrib.fsm_storage.memory.MemoryStorage |
aiogram.fsm.storage.memory.MemoryStorage |
All of these come from aiogram’s migration guide[1], which lists many more: keyboards, callback data, middlewares, exceptions, i18n.
The errors that come next
The same migration produces a family of errors. Each is the same cause, a line written for aiogram 2, and is fixed by the table above. Run on aiogram 3 today, they read:
| Error | The aiogram 2 line |
|---|---|
TypeError: Dispatcher.__init__() takes 1 positional argument but 2 were given |
dp = Dispatcher(bot): the initializer now takes keyword arguments only[3] |
AttributeError: 'Dispatcher' object has no attribute 'message_handler' |
@dp.message_handler(...) |
ModuleNotFoundError: No module named 'aiogram.contrib' |
from aiogram.contrib.fsm_storage.memory import MemoryStorage |
ModuleNotFoundError: No module named 'aiogram.dispatcher.filters' |
from aiogram.dispatcher.filters import Text (the Text filter has no 3.x equivalent; use F.text)[1] |
ImportError: cannot import name 'FSMContext' from 'aiogram.dispatcher' |
now from aiogram.fsm.context import FSMContext |
ImportError: cannot import name 'ParseMode' from 'aiogram.types' |
now from aiogram.enums import ParseMode |
TypeError: Passing `parse_mode`, `disable_web_page_preview` or `protect_content` to Bot initializer is not supported anymore |
Bot(token, parse_mode="HTML"): removed in 3.7.0, the message names the replacement[7] |
On Python 3.9 and older the first TypeError reads __init__() without the class name; the cause is the same.
Some changes raise nothing at all, and aiogram’s migration guide marks them as the dangerous group[1]: a bare handler that now receives stickers and photos, parse_mode=None in a call, which now turns formatting off instead of using the bot’s default, and await bot.me, which is now a method, await bot.me(). After the rewrite, test the bot with a sticker, a photo and every command before you deploy it.
Why pinning aiogram 2 is a dead end
The quick way out is to install the version the code was written for:
aiogram==2.25.2
It works as a stopgap, and it costs more every month:
- No more releases. 2.25.2, from October 2023, is the last 2.x release; everything since is 3.x[8].
- Old dependencies. aiogram 2.25.2 requires aiohttp 3.8[9]. aiohttp 3.8.6, the last 3.8 release, ships ready-built wheels only up to Python 3.11[10], so on Python 3.12 or newer pip has to compile it from source. When that fails, see Failed building wheel.
- The rewrite is still ahead. The migration only grows with the code you add on top of aiogram 2.
If you pin, pin Python too (3.11 or older), and treat it as time to do the rewrite, not instead of it. Going the other way, current aiogram 3 releases declare Python 3.11 or newer, below 3.16[8].
On Livops
What Livops does with an aiogram bot, and what it does not:
-
It installs what
requirements.txtnames. An unpinnedaiogramline gets the current 3.x release on every deploy, the same as on any fresh machine. Write the major version you mean:aiogram>=3,<4once the code is rewritten. -
The error stops the deploy as
start_failed. The build passes, the bot fails as it starts, and the traceback is on the project’s Logs page. A bot’s previous version is stopped before the new one starts, because two copies polling Telegram would conflict, so the bot is down until a deploy succeeds. Run the rewritten bot locally first. -
You choose the Python. Livops runs Python 3.10 to 3.14 and reads the version from a
.python-versionfile at the project root. For current aiogram 3, use 3.11 or newer; for the aiogram 2 stopgap, 3.11 is the newest Python with ready aiohttp 3.8 wheels. -
The start command. Livops finds
bot.py,main.py,app.pyorrun.pyby itself. To name it, write.venv/bin/python bot.pyin Settings → Start, or aProcfile:worker: .venv/bin/python bot.py -
The token is a variable. Put it under Settings → Variables as
BOT_TOKEN, which the code above reads. -
Starting fresh is also an option: the aiogram 3 bot + Redis template creates an aiogram 3 bot together with a Redis database.
A bot costs 19 credits a month (19,000 so’m). A VPS is the better fit when you run many bots on one machine, or a bot needs root for system packages of its own; on Livops a push is the deploy and restarts are the platform’s job, but there is no root. Hosting details are in aiogram bot hosting, and startup failures in The app did not start.
Questions
Why did this start without any change to my code?
Your requirements.txt names aiogram without a version, or with only a lower bound, so a fresh install picked the current 3.x release. The code was written for aiogram 2. Check the installed version with pip show aiogram.
Can I just import executor from somewhere else?
No. aiogram 3 removed the executor completely, not only moved it. from aiogram.utils import executor fails the same way. The Dispatcher starts polling itself with await dp.start_polling(bot).
Is pinning aiogram 2 a real fix?
It is a stopgap. The last 2.x release, 2.25.2, came out in October 2023 and needs aiohttp 3.8, which has no ready-built wheels for Python 3.12 or newer. The rewrite to aiogram 3 still has to happen.
What replaces dp.message_handler?
dp.message, or router.message on a Router you include into the Dispatcher. aiogram 3 dropped the _handler suffix from every decorator, so callback_query_handler becomes callback_query as well.
Why does my text handler now crash on stickers and photos?
A bare v2 handler only received text messages outside any FSM state. A bare v3 handler receives every content type in every state. Add the filter explicitly: dp.message(F.text).
Which Python does aiogram 3 need?
The current 3.x release on PyPI declares Python 3.11 or newer, below 3.16. On an older Python pip installs an older 3.x release or none at all.
Does Livops rewrite aiogram 2 code for me?
No. Livops installs what requirements.txt names and starts your bot. When the bot fails at startup, the deploy stops as start_failed and the traceback is on the Logs page; the rewrite is yours.
Sources
- aiogram docs source — Migration FAQ (2.x -> 3.x) (github.com). Checked .
- aiogram source — aiogram/__init__.py (github.com). Checked .
- aiogram source — aiogram/dispatcher/dispatcher.py (github.com). Checked .
- aiogram docs source — Dispatcher (github.com). Checked .
- aiogram — examples/echo_bot.py (3.x) (github.com). Checked .
- aiogram — examples/echo_bot.py (2.x) (github.com). Checked .
- aiogram source — aiogram/client/bot.py (github.com). Checked .
- PyPI — aiogram, release history (pypi.org). Checked .
- PyPI — aiogram 2.25.2 (pypi.org). Checked .
- PyPI — aiohttp 3.8.6, files (pypi.org). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- aiogram bot hosting: how to deploy an aiogram 3 botAn aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.
- RuntimeError: This event loop is already running — how to fix it in a Telegram botRuntimeError: This event loop is already running, and its sibling asyncio.run() cannot be called from a running event loop, mean the code tried to start an asyncio event loop inside one that is already running: python-telegram-bot's run_polling inside your own asyncio.run, aiogram's run_polling inside an async main, asyncio.run inside a handler, or a Jupyter notebook. Start the loop once, at the bottom of the program, and await everything inside it.
- Conflict: terminated by other getUpdates request — how to fix itTelegram is telling your bot that another process called getUpdates with the same token and took the connection over. Two copies of the bot are polling at once: stop the other one (usually the copy still running on your computer or an old server), or get a new token from @BotFather, and the error stops.
- ModuleNotFoundError: No module named — after a deployPython searched sys.path and could not find the module you import. After a deploy that almost always means the package is not in requirements.txt, is listed under a different name than the one you import, or the start command runs a Python that the packages were not installed into.
- pip: Failed building wheel / failed-wheel-build-for-install — how to fix itpip found no ready-made wheel for a package on your Python version and platform, tried to compile one from source, and the compiler step failed. The fix is almost never to install a compiler: move to a version of the package that ships a wheel for your Python, switch to its binary variant (psycopg[binary], psycopg2-binary), or pin the Python version the package supports.
- Telegram bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.
- AttributeError: 'Updater' object has no attribute 'dispatcher': how to fix itAttributeError: 'Updater' object has no attribute 'dispatcher' means code written for python-telegram-bot v13 is running on v20 or newer. Version 20 moved to asyncio and replaced the Updater and Dispatcher pair with Application: build it with ApplicationBuilder().token(...).build(), register handlers with application.add_handler, make the handlers async, and start with application.run_polling(). Pinning python-telegram-bot==13.15 only buys time.
- TelegramNetworkError: HTTP Client says - ClientConnectorError (aiogram): how to fix itaiogram.exceptions.TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 means the bot could not open a connection to Telegram's Bot API at all: the code and the token are not the problem, the network is. The usual causes are a network that blocks Telegram, DNS, a missing or broken proxy, a bad IPv6 route, a server with no outbound access, or a slow path that ends in timeouts. Test the same path with curl, then fix the network, set aiogram's proxy, or run the bot where api.telegram.org is reachable.