我机器上同时存在python2.7、python3.5、python3.6,想在python3.5上安装torch,想着用pip3.5直接安装:
$ pip3.5 install torch
噢噢,提示权限不够:Permission Denied: [Errno 13] Permission denied...。
这个好办,加个--user参数,直接装到个人用户目录下,try again:
$ pip3.5 install torch --user
Traceback (most recent call last):
File "/usr/local/bin/pip3.5", line 6, in
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3098, in
@_call_aside
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3082, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3111, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 573, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 891, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 777, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==8.1.1' distribution was not found and is required by the application
这就尴尬了,说是pip需要8.1.1的版本。好,那就给python3.5装个pip 8.1.1:
#获取get-pip.py,这个是用来安装pip的官方工具
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
#使用python.3.5执行上面获取的get-pip.py,指定安装pip 8.1.1到自己的账户。
$ python3.5 get-pip.py pip=8.1.1 --user
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pip==8.1.1
Using cached https://mirrors.aliyun.com/pypi/packages/31/6a/0f19a7edef6c8e5065f4346137cc2a08e22e141942d66af2e1e72d851462/pip-8.1.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.0.3
Uninstalling pip-19.0.3:
Successfully uninstalled pip-19.0.3
Successfully installed pip-8.1.1
国内的源,速度还不错!
# 再看我账户下现在pip3.5的版本,已经是8.1.1了
$ pip3.5 --version
pip 8.1.1 from /home/xx/.local/lib/python3.5/site-packages (python 3.5)
#再来装torch就ok了!
$ pip3.5 install torch --user
Collecting torch
Cache entry deserialization failed, entry ignored
Downloading https://mirrors.aliyun.com/pypi/packages/59/d2/4e806f73b4b72daab9064c99394fc22ea6ef1fb052154546405057cd192d/torch-1.0.1.post2-cp35-cp35m-manylinux1_x86_64.whl (582.5MB)
100% |████████████████████████████████| 582.5MB 3.5kB/s
Installing collected packages: torch
Successfully installed torch-1.0.1.post2
【参考文档】
https://pip.pypa.io/en/stable/installing/