在开发环境中同时安装多个 Python 版本是一种常见的情况,本文将介绍在Python2.7和Python3.6共存的环境中,如何使用 Python 3.6 的 pip 安装其他包(如scikit-learn)。
步骤:
-
确定 Python 3.6 的 pip 路径:
首先需要找到 Python 3.6 的 pip 路径,例如:C:\Users\Jack\AppData\Local\Programs\Python\Python36\Scripts\pip
-
使用 Python 3.6 的 pip 安装新的包,例如: scikit-learn:
在命令提示符中运行以下命令来使用 Python 3.6 的 pip 安装 scikit-learn:C:\Users\Jack\AppData\Local\Programs\Python\Python36\Scripts\pip install scikit-learn
-
验证安装:
安装完成后,可以在 Python 3.6 的环境中尝试导入 scikit-learn 库,先进入Python 3.6的交互式环境:C:\Users\Jack\AppData\Local\Programs\Python\Python36\python
然后在 Python 交互式环境中尝试导入 scikit-learn:
import sklearn
如果没有报错,说明 scikit-learn 已成功安装。