python导入scipy库、sympy库遇到的问题及解决方式

首先从cmd中导入scipy库,输入代码:

pip install scipy

注意: pip版本最好也要更新到最新版,否则容易发生版本冲突的问题。
但是出现异常:read time out
这时想到的解决方式是修改默认的时间:

pip --default-timeout=100 install scipy

仍然不能解决,出现上述异常。
然后查看自己需要安装的scipy版本是否正确,,进入python命令行中,输入代码:

import wheel.pep425tags as w
print(w.get_supported())

但是会出现异常:

get_supported() missing 1 required positional argument: ‘archive_root’

这时需要在括号中写入"archive_root"即可:

import wheel.pep425tags as w
print(w.get_supported("archive_root"))

问题得到解决,可以输出以下信息:

[('cp37', 'cp37m', 'win_amd64'), ('cp37', 'none', 'win_amd64'), ('cp37', 'none', 'any'), ('cp3', 'none', 'any'), ('cp36', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'win_amd64'), ('py37', 'none', 'any'), ('py3', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

根据上面的‘cp37’、‘win_amd64’可以知道应该安装的版本。到Unofficial Windows Binaries for Python Extension Packages下载正确的scipy库版本即可。
下载界面如图所示:
python导入scipy库、sympy库遇到的问题及解决方式_第1张图片
这里我查阅了网络,有一些其他的解决方式,但是我都不行,但避免以后遇到问题,还是在这里写一下
对于python3.x版本:

import pip._internal
print(pip._internal.pep425tags.get_supported())

对于python2.x版本:

import pip
print(pip.pep425tags.get_supported())

但是上面的两个方式我都出现问题:

module pip._internal has no attribute pep425tags 或者 module pip has no attribute pep425tags

将正确的版本下载到python文件夹的scripts下之后,进行安装。
注意 :这里有个坑,如果从cmd中进入到下载的文件夹下,输入代码pip install scipy-1.5.2-cp37-cp37m-win_amd64.whl。那么再次pip list会发现,此时石油scipy库的,但是依然不能import这个库。然而当退出这个路径后,输入pip list,发现还是没有scipy库。
所以这里需要进行的正确操作是:在cmd中直接输入代码

pip install C:\Users\Zhao Zihan\AppData\Local\Programs\Python\Python38\Scripts\scipy-1.5.2-cp37-cp37m-win_amd64.whl

当然,这里会有路径中含有空格的问题,所以需要在路径外添加双引号,即:

pip install "C:\Users\Zhao Zihan\AppData\Local\Programs\Python\Python38\Scripts\scipy-1.5.2-cp37-cp37m-win_amd64.whl"

这样再次pip list就能发现下载成功,也可以进行import了。
最后是下载和导入sympy库,下载方式与上文的连接相同。所以这里不作赘述。
这里借鉴了以下博文:

  • module pip._internal has no attribute pep425tags 或者 module pip has no attribute pep425tags
  • wheel.pep425tags.getsupported()报错解决方法
  • Python 语法问题-module ‘pip’ has no attribute ‘pep425tags’,告诉你如何正确查看pip支持,32位、64位查看pip支持万能方法

你可能感兴趣的:(python学习,python)