使用 pip 安装 scikit-learn:我的计算机上是否安装了多个 python 版本?

Installing scikit-learn with pip: are there multiple python versions installed on my computer?

我正在尝试使用 pip install scikit-learn 通过 pip 安装 scikit-learn 我收到了这条消息:

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

WARNING: The scripts f2py, f2py2 and f2py2.7 are installed in '/Users/my_name/Library/Python/2.7/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

但是,当我输入 python --version 时,它说我的版本是 3.7.4。那么 python 2.7 和 3.7 都安装在我的电脑上了吗?如果是这样,有没有办法摆脱 2.7?此外,当我在 mu_editor 中执行 from sklearn.cluster import MeanShift 时,我仍然得到 ModuleNotFoundError。我认为这是因为 pip 正在将模块安装到 python 2.7 目录或其他目录,而不是 mu_editor 连接到的 python 3.7.4 目录。有什么方法可以将软件包安装到 python 3.7.4 目录而不是 2.7 目录?

首先,使用 python -v 检查默认 python 安装。如果它是您正在使用的版本,请继续使用 python 而不是 python3

现在运行python3 -m pip install scikit-learn 如果您使用 Mac,请不要删除 PYTHON 2.7。您的系统需要它才能正常 运行。