python-telegram-bot环境处理过程中的错误
在运行脚本时报错
一、没有telegram
环境
ModuleNotFoundError: No module named 'telegram'
这是因为本机没有安装python-telegram-bot
或者一些特殊原因,安装的这个环境出问题了,需要重新安装
1
2
3
4
5
# python3 安装
pip3 install python-telegram-bot --upgrade
# 如果是python2,使用如下指令安装
pip install python-telegram-bot --upgrade
二、python环境不正确
error: externally-managed-environment
This environment is externally managed ╰─> To install Python packages system-wide, try brew install xyz, where xyz is the package you are trying to install.If you wish to install a Python library that isn’t in Homebrew, use a virtual environment:
python3 -m venv path/to/venv source path/to/venv/bin/activate python3 -m pip install xyz
If you wish to install a Python application that isn’t in Homebrew, it may be easiest to use ‘pipx install xyz’, which will manage a virtual environment for you. You can install pipx with
brew install pipx
You may restore the old behavior of pip by passing the ‘–break-system-packages’ flag to pip, or by adding ‘break-system-packages = true’ to your pip.conf file. The latter will permanently disable this error.
If you disable this error, we STRONGLY recommend that you additionally pass the ‘–user’ flag to pip, or set ‘user = true’ in your pip.conf file. Failure to do this can result in a broken Homebrew installation.
Read more about this behavior here: https://peps.python.org/pep-0668/
按提示进行配置即可
1
2
3
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
三、安装xyz报错
ERROR: Could not find a version that satisfies the requirement xyz (from versions: none)
[notice] A new release of pip is available: 24.2 -> 24.3.1 [notice] To update, run: pip install –upgrade pip ERROR: No matching distribution found for xyz pip install –upgrade pip
按提示安装升级即可
1
pip install --upgrade pip