pip pytorch安装时出现的问题

pytorch 的安装命令在官网就有,这里就不说了

执行安装命令

pip3 install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl 

 报错如下

可以知道是pip的版本太旧了,因此要更新pip的版本,用如下命令

sudo apt install python-pip

但是又报依赖关系出现问题

Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: 处理软件包 python-pip (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 1
正在设置 python-pkg-resources (20.7.0-1) ...
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: 处理软件包 python-pkg-resources (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 1
dpkg: 依赖关系问题使得 python-setuptools 的配置工作不能继续:
 python-setuptools 依赖于 python-pkg-resources (= 20.7.0-1);然而:
  软件包 python-pkg-resources 尚未配置。

dpkg: 处理软件包 python-setuptools (--configure)时出错:
 依赖关系问题 - 仍未被配置
正在设置 python-wheel (0.29.0-1) ...
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
                                                                    Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: 处理软件包 python-wheel (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 1
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    在处理时有错误发生:
 python-pip
 python-pkg-resources
 python-setuptools
 python-wheel
E: Sub-process /usr/bin/dpkg returned an error code (1)

在安装是无法识别 ConfigParser一些包无法正确安装引起的,原因其实是我之前将python3设为系统的默认版本,
在Python 3中, ConfigParser 被重命名为 configparser
如果默认版本是Python3执行更新操作会报错

所以要切回python2才能正确安装

解决方案:
切换Python版本

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 200
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100

如果要切回python3.x的话

mv /usr/bin/python /usr/bin/python2.x //对系统默认版本python进行操作  
ln -s /usr/local/bin/python3.x /usr/bin/python   //注意第一个路径是新安装的python版本路径,而第二个路径是系统默认路径  

 

但是这样还是无法解决pytorch无法安装的问题,仍然报错

You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

 但是pip install --upgrade pip并不能升级到version 9.0.1

解决方案:

使用wget安装成功,具体如下:
sudo apt-get update
sudo apt-get upgrade
wget https://bootstrap.pypa.io/get-pip.py

sudo python3 get-pip.py


sudo apt-get install build-essential python-dev
sudo pip install uwsgi

但是不知道为什么,当我执行命令pip3 install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl时,

lai@lai-To-be-filled-by-O-E-M:~$ pip3 install torchvision
bash: /usr/bin/pip3: 没有那个文件或目录

 只有root权限才能正常安装

lai@lai-To-be-filled-by-O-E-M:~$ sudo pip3 install torchvision
The directory '/home/lai/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/lai/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting torchvision
  Downloading torchvision-0.1.9-py2.py3-none-any.whl (43kB)
    100% |████████████████████████████████| 51kB 88kB/s 
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (from torchvision)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from torchvision)
Requirement already satisfied: numpy in ./.local/lib/python3.5/site-packages (from torchvision)
Requirement already satisfied: torch in ./.local/lib/python3.5/site-packages (from torchvision)
Requirement already satisfied: pyyaml in ./.local/lib/python3.5/site-packages (from torch->torchvision)
Installing collected packages: torchvision
Successfully installed torchvision-0.1.9

 

转载于:https://www.cnblogs.com/lindaxin/p/7943720.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值