Windows 上的导入错误
ImportError on Windows
我试图在 Windows 机器上 运行 我的 Python 脚本,但我得到这个错误:
"Traceback (most recent call last):
File "D:\Python\telegram\main.py", line 4, in <module>
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
File "C:\Users\Balcony\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\__init__.py", line 27, in <module>
from .jobqueue import JobQueue, Job
File "C:\Users\Balcony\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\jobqueue.py", line 26, in <module>
import pytz
ModuleNotFoundError: No module named 'pytz'"
我的代码:
import logging
import requests
import re
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram.ext import KeyboardButton
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Define a few command handlers. These usually take the two arguments update and
# context. Error handlers also receive the raised TelegramError object in error.
def start(update, context):
"""Send a message when the command /start is issued."""
update.message.reply_text('Hi!')
def help(update, context):
"""Send a message when the command /help is issued."""
update.message.reply_text(f'Help! 1234')
def echo(update, context):
"""Echo the user message."""
update.message.reply_text(f'Вы написали: {update.message.text}')
print(update.message.text)
当然,我安装了所有的包。
并且同一个 py 文件在 MacOS 上可以正常工作
从 telegram.ext 导入更新程序
添加.ext
我试图在 Windows 机器上 运行 我的 Python 脚本,但我得到这个错误:
"Traceback (most recent call last):
File "D:\Python\telegram\main.py", line 4, in <module>
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
File "C:\Users\Balcony\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\__init__.py", line 27, in <module>
from .jobqueue import JobQueue, Job
File "C:\Users\Balcony\AppData\Local\Programs\Python\Python39\lib\site-packages\telegram\ext\jobqueue.py", line 26, in <module>
import pytz
ModuleNotFoundError: No module named 'pytz'"
我的代码:
import logging
import requests
import re
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram.ext import KeyboardButton
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Define a few command handlers. These usually take the two arguments update and
# context. Error handlers also receive the raised TelegramError object in error.
def start(update, context):
"""Send a message when the command /start is issued."""
update.message.reply_text('Hi!')
def help(update, context):
"""Send a message when the command /help is issued."""
update.message.reply_text(f'Help! 1234')
def echo(update, context):
"""Echo the user message."""
update.message.reply_text(f'Вы написали: {update.message.text}')
print(update.message.text)
当然,我安装了所有的包。
并且同一个 py 文件在 MacOS 上可以正常工作
从 telegram.ext 导入更新程序
添加.ext