Forums

ImportError: PyO3 modules may only be initialized once per interpreter process

Hello everyone, I got an error when I wanted to load a telegram bot written in aiogram 3x on pythonanywhere: ImportError: PyO3 modules may only be initialized once per interpreter process.

Here is the code:

from aiogram import Bot, Dispatcher, types
import asyncio
import logging
from aiogram import F


dp = Dispatcher()
bot = Bot(token='TOKEN')
logging.basicConfig(level=logging.INFO)
proxy_url = 'http://proxy.server:3128'


@dp.message(F.text)
async def eho_bot(message: types.Message):
    await message.answer(message.text)


async def main():
    proxy = types.Proxy(type=types.ProxyType.HTTP, url=proxy_url)
    await bot.set_proxy(proxy)
    await dp.start_polling(bot, skip_updates=True)

if __name__ == "__main__":
    asyncio.run(main())

Help me fix it please. (I'm uploading for the first time, sorry for the English, I'm using Google translator)

You're not using PyO3 here directly, so it must be used somewhere else in your codebase or in one of your dependencies. You could try importing each dependency one by one to isolate where it's coming from.