版权声明:站在巨人的肩膀上学习。 https://blog.csdn.net/zgcr654321/article/details/85177874
系统环境
本教程系统平台为win7 64位旗舰版。
python中使用pip安装模块的方法
使用下面的命令来安装模块:
python -m pip install 模块名
一般情况下,使用上面的命令就可以安装成功。
如何知道我们的python模块安装到哪个位置
这个问题常见于我们的系统平台中存在多个python环境时,比如我们的系统中同时存在python2.7和python3.6,又比如我们的Anaconda中安装了多个不同的python版本的环境。
这种情况下,如果我们使用cmd来执行命令:
python -m pip install 模块名
那么安装的位置取决于我们的用户环境变量path中哪一个含有python.exe的路径在path的最前面,在cmd中输入python执行时总是执行path路径中第一个含有python.exe路径中的python。
如果我们使用anaconda prompt,只要我们先使用命令:
activate 环境名
然后再执行:
python -m pip install 模块名
这时模块就会安装在上面activate的那个环境中。
Cannot uninstall X错误的解决方法
有时我们会遇到Cannot uninstall X这类错误,提示类似下面的代码:
Installing collected packages: numpy
Found existing installation: numpy 1.8.2
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
出现这种错误的原因是我们在新安装B包时,以前安装的A包中含有一些B包中要安装的模块,而Python并不知道这些模块中是A包中的版本比较新还是B包中的版本比较新,所以选择中止安装。
我们可以使用命令:
pip install 模块名 --ignore-installed
来解决这个冲突,这样遇到已安装过的模块时就会跳过这个模块。