1. 原因
由于忘记切换conda得环境,我执行了pip uninstall -r requirements.txt命令,导致pip被卸载了,只要执行conda env list 就会提示如下错误:
% conda env list
Traceback (most recent call last):
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/gateways/connection/__init__.py", line 21, in <module>
from requests import ConnectionError, HTTPError, Session
ModuleNotFoundError: No module named 'requests'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/charles/miniconda3/bin/conda-env", line 6, in <module>
from conda_env.cli.main import main
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda_env/cli/main.py", line 13, in <module>
import conda.exports # noqa
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/exports.py", line 25, in <module>
from . import plan # NOQA
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/plan.py", line 25, in <module>
from .core.index import LAST_CHANNEL_URLS, _supplement_index_with_prefix
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/index.py", line 13, in <module>
from .package_cache_data import PackageCacheData
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/package_cache_data.py", line 14, in <module>
from .path_actions import CacheUrlAction, ExtractPackageAction
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/path_actions.py", line 30, in <module>
from ..gateways.connection.download import download
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/gateways/connection/__init__.py", line 39, in <module>
from pip._vendor.requests import ConnectionError, HTTPError, Session
ModuleNotFoundError: No module named 'pip'
charles@charles /mnt/d/PycharmProjects/threshold
% conda activate threshold
charles@charles /mnt/d/PycharmProjects/threshold
% conda env list
Traceback (most recent call last):
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/gateways/connection/__init__.py", line 21, in <module>
from requests import ConnectionError, HTTPError, Session
ModuleNotFoundError: No module named 'requests'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/charles/miniconda3/bin/conda-env", line 6, in <module>
from conda_env.cli.main import main
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda_env/cli/main.py", line 13, in <module>
import conda.exports # noqa
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/exports.py", line 25, in <module>
from . import plan # NOQA
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/plan.py", line 25, in <module>
from .core.index import LAST_CHANNEL_URLS, _supplement_index_with_prefix
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/index.py", line 13, in <module>
from .package_cache_data import PackageCacheData
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/package_cache_data.py", line 14, in <module>
from .path_actions import CacheUrlAction, ExtractPackageAction
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/core/path_actions.py", line 30, in <module>
from ..gateways.connection.download import download
File "/home/charles/miniconda3/lib/python3.9/site-packages/conda/gateways/connection/__init__.py", line 39, in <module>
from pip._vendor.requests import ConnectionError, HTTPError, Session
ModuleNotFoundError: No module named 'pip'
2. 解决办法
conda activate base # 为了保险起见,先切换到base
python -m ensurepip
python -m pip install --upgrade pip