最近用Debian遇到python3提示缺少某个库,运行不了。找了些资料,解决如下。
首先安装pip工具
1.1 yum -y install python-setuptools ubuntu使用apt-get install python-setuptools
1.2 python -m pip install –upgrade pip
1.3安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip -V #查看pip版本
2.升级python到3.7版本
https://www.cnblogs.com/zydeboke/p/11465890.html 原文链接
[root@ansible soft]# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
[root@ansible soft]# tar xvf Python-3.7.3.tar.xz
[root@ansible soft]# cd Python-3.7.3/
[root@ansible Python-3.7.3]# ./configure
[root@ansible Python-3.7.3]# make
[root@ansible Python-3.7.3]#make install
将原来 python 的软链接重命名:
# mv /usr/bin/python /usr/bin/python.bak
将 python 链接至 python3:
# ln -s /usr/local/bin/python3 /usr/bin/python
修改/usr/bin/yum和/usr/libexec/urlgrabber-ext-down,将 #!/usr/bin/python 改为 #!/usr/bin/python2.7,保存退出即可
[root@ansible-admin Python-3.7.3]# vi /usr/bin/yum
[root@ansible-admin Python-3.7.3]# vi /usr/libexec/urlgrabber-ext-down
3.安装yaml(安装包,遇到的问题即解决方法)
3.1 pip install pyyaml
3.2 python -m pip install numpy
3.3 pip install pycuda
出现的问题:
3.3.1ModuleNotFoundError: No module named ‘_ctypes‘的解决办法
#apt-get install libffi-devel -y
#make install
#pip install pycuda
3.4 pip install matplotlib==2.2.3
3.5 问题:No module named ‘_tkinter’
yum install -y tkinter
yum install -y tk-devel
cd Python-3.7.3/
.configure
make
make install
3.6 问题:No module named ‘seaborn’
pip install seaborn
3.7 No module named ‘_bz2
yum install bzip2-devel
将_bz2.cpython-37m-x86_64-linux-gnu.so下载放到/usr/local/lib/python3.7/lib-dynload/即可
3.8 no display name and no $DISPLAY environment variable
修改.py
import matplotlib
matplotlib.use(‘Agg’)