ModuleNotFoundError: нет модуля с именем «aiogram».Python

Программы на Python
Ответить
Anonymous
 ModuleNotFoundError: нет модуля с именем «aiogram».

Сообщение Anonymous »

Я работаю в VS Code, и меня попросили изменить скрипт бота Telegram с библиотеки python-telegram-bot на aiogram. Я установил его с помощью «pip install aiogram», но все равно получаю такие ошибки, как ModuleNotFoundError: нет модуля с именем «aiogram», и я не знаю, что делать.

Код: Выделить всё

import logging
from aiogram import Bot, Dispatcher, types
from aiogram.types import ParseMode
from aiogram.utils import executor
import requests

TELEGRAM_BOT_TOKEN = 'XXXXXXXX'
COINGECKO_API_KEY = 'XXXXXXXX'

logging.basicConfig(level=logging.INFO)

bot = Bot(token=TELEGRAM_BOT_TOKEN)
dp = Dispatcher(bot)

# Function to get token price from CoinGecko
def get_token_price(token_id):
url = f'https://api.coingecko.com/api/v3/simple/price?ids={token_id}&vs_currencies=usd'
headers = {'Authorization': f'Bearer {COINGECKO_API_KEY}'}
response = requests.get(url, headers=headers)
data = response.json()

if 'error' in data:
logging.error(f'Error from CoinGecko API: {data["error"]}')
return None

try:
price = data[token_id]['usd']
return price
except KeyError:
logging.error(f'KeyError: Could not find price for token with ID {token_id}')
return None

# Command handlers
@dp.message_handler(commands=['btc'])
async def get_btc(message: types.Message):
price = get_token_price('bitcoin')
if price is not None:
await message.reply(f'Ціна Bitcoin: {price} USD')
else:
await message.reply('Не вдалося отримати ціну для Bitcoin')

@dp.message_handler(commands=['eth'])
async def get_eth(message: types.Message):
price = get_token_price('ethereum')
if price is not None:
await message.reply(f'Ціна Ethereum: {price} USD')
else:
await message.reply('Не вдалося отримати ціну для Ethereum')

@dp.message_handler(commands=['sfund'])
async def get_sfund(message: types.Message):
price = get_token_price('seedify-fund')
if price is not None:
await message.reply(f'Ціна Seedify: {price} USD')
else:
await message.reply('Не вдалося отримати ціну для Seedify Fund')

@dp.message_handler(commands=['cgpt'])
async def get_cgpt(message: types.Message):
price = get_token_price('chaingpt')
if price is not None:
await message.reply(f'Ціна ChainGPT: {price} USD')
else:
await message.reply('Не вдалося отримати ціну для ChainGPT')

@dp.message_handler(commands=['bnb'])
async def get_bnb(message: types.Message):
price = get_token_price('binancecoin')
if price is not None:
await message.reply(f'Ціна BNB: {price} USD')
else:
await message.reply('Не вдалося отримати ціну для Binance Coin (BNB)')

if __name__ == '__main__':
from aiogram import executor
executor.start_polling(dp, skip_updates=True)
Пытался создать новый проект (иногда помогает) и все та же ошибка

Подробнее здесь: https://stackoverflow.com/questions/778 ... ed-aiogram
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»