1、准备环境和软件
安装环境:windows + 已安装python2.7版本
准备安装:pyenv2.64.3 + virtualenvwrapper
python下载地址(注意下载64位的不然会报错平台不适配,以前用pep425tags版本信息
):
https://www.python.org/downloads/
通过pip命令查看python的版本:
pip debug --verbose
(pytorch381) F:\pytorch>pip debug --verbose
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 20.2.2 from c:\users\nile-ssd\envs\pytorch381\lib\site-packages\pip (python 3.8)
sys.version: 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
sys.executable: c:\users\nile-ssd\envs\pytorch381\scripts\python.exe
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: cp936
sys.platform: win32
sys.implementation:
name: cpython
'cert' config value: global
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): c:\users\nile-ssd\envs\pytorch381\lib\site-packages\pip\_vendor\certifi\cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
appdirs==1.4.4
CacheControl==0.12.6
colorama==0.4.3
contextlib2==0.6.0.post1 (Unable to locate actual module version, using vendor.txt specified version)
distlib==0.3.1
distro==1.5.0 (Unable to locate actual module version, using vendor.txt specified version)
html5lib==1.1
ipaddress==1.0.23
msgpack==1.0.0 (Unable to locate actual module version, using vendor.txt specified version)
packaging==20.4
pep517==0.8.2
progress==1.5
pyparsing==2.4.7
requests==2.24.0
certifi==2020.06.20
chardet==3.0.4
idna==2.10
urllib3==1.25.9
resolvelib==0.4.0
retrying==1.3.3 (Unable to locate actual module version, using vendor.txt specified version)
setuptools==44.0.0 (Unable to locate actual module version, using vendor.txt specified version)
six==1.15.0
toml==0.10.1
webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 30
cp38-cp38-win_amd64
cp38-abi3-win_amd64
cp38-none-win_amd64
cp37-abi3-win_amd64
cp36-abi3-win_amd64
cp35-abi3-win_amd64
cp34-abi3-win_amd64
cp33-abi3-win_amd64
cp32-abi3-win_amd64
py38-none-win_amd64
py3-none-win_amd64
py37-none-win_amd64
py36-none-win_amd64
py35-none-win_amd64
py34-none-win_amd64
py33-none-win_amd64
py32-none-win_amd64
py31-none-win_amd64
py30-none-win_amd64
cp38-none-any
py38-none-any
py3-none-any
py37-none-any
py36-none-any
py35-none-any
py34-none-any
py33-none-any
py32-none-any
py31-none-any
py30-none-any
(pytorch381) F:\pytorch>
python版本(pyenv):3.8.1(64位)
pytorch版本:torch-1.6.0+cpu-cp38-cp38-win_amd64.whl
2、pyenv安装:
pip install pyenv-win --target E:\pyenv\.pyenv
添加环境变量:
在windows 下 pyenv并不是有友好,网上搜索了很多朋友的文章,但是最后安装版本的时候都没有成功,python-3.8.1-amd64-webinstall.exe这种最终都没有安装成功,msi的没有问题,有知道为什么的可以指点下,谢谢!
网上有修改国内下载源的方法,主要是为了下载更快,我更新了阿里的,更新后记得pyenv update,不然配置源文件还是官方的。
pyenv 2.64.3版本的源更新文件:
pyenv update
我的解决方法:
单独下载python独立安装包,放到E:\pyenv\.pyenv\pyenv-win\versions下面,或者直接安装到该目录
C:\Users\nile-ssd>pyenv versions
2.7.14
3.4.4
3.8.1
3.8.5
3.8.5_64
C:\Users\nile-ssd>pyenv shell 3.8.5
C:\Users\nile-ssd>pyenv rehash
C:\Users\nile-ssd>python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Users\nile-ssd>pyenv shell 2.7.14
C:\Users\nile-ssd>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
可以自由切换了!
3、virtualenvwrapper-win安装:
pip install virtualenvwrapper-win
C:\Users\nile-ssd>workon
Pass a name to activate one of the following virtualenvs:
==============================================================================
pytorch381
C:\Users\nile-ssd>mkvirtualenv --python = E:\pyenv\.pyenv\pyenv-win\versions\3.8.5_64\python.exe pytorch385
Running virtualenv with interpreter E:\pyenv\.pyenv\pyenv-win\versions\3.8.5_64\python.exe
Already using interpreter E:\pyenv\.pyenv\pyenv-win\versions\3.8.5_64\python.exe
Using base prefix 'E:\\pyenv\\.pyenv\\pyenv-win\\versions\\3.8.5_64'
New python executable in C:\Users\nile-ssd\Envs\pytorch385\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
(pytorch385) C:\Users\nile-ssd>python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
4、安装pytouch
方法一:线上安装:
由于线上安装下载比较慢,可选择下载后安装
方法二:
下载地址:
https://download.pytorch.org/whl/torch_stable.html
选择python合适的版本:
(pytorch385) F:\pytorch>pip install "torch-1.6.0+cpu-cp38-cp38-win_amd64.whl"
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Processing f:\pytorch\torch-1.6.0+cpu-cp38-cp38-win_amd64.whl
Processing c:\users\nile-ssd\appdata\local\pip\cache\wheels\81\66\8d\d48705a24664587f61557810d796603caef2610c98b3a24b44\future-0.18.2-py3-none-any.whl
Collecting numpy
Downloading http://mirrors.aliyun.com/pypi/packages/c7/7d/ea9e28c3a99f50e77ee9a0e3759adb6537b2bb7a84aef27b8c0ddc431b48/numpy-1.19.1-cp38-cp38-win_amd64.whl (13.0 MB)
|████████████████████████████████| 13.0 MB 2.2 MB/s
Installing collected packages: future, numpy, torch
Successfully installed future-0.18.2 numpy-1.19.1 torch-1.6.0+cpu
(pytorch385) F:\pytorch>pip install "torchvision-0.7.0+cpu-cp38-cp38-win_amd64.whl"
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Processing f:\pytorch\torchvision-0.7.0+cpu-cp38-cp38-win_amd64.whl
Requirement already satisfied: torch==1.6.0 in c:\users\nile-ssd\envs\pytorch385\lib\site-packages (from torchvision==0.7.0+cpu) (1.6.0+cpu)
Requirement already satisfied: numpy in c:\users\nile-ssd\envs\pytorch385\lib\site-packages (from torchvision==0.7.0+cpu) (1.19.1)
Collecting pillow>=4.1.1
Downloading http://mirrors.aliyun.com/pypi/packages/91/d2/30ecd905746d1fee4004daae3f0051bf4b305bee1fe578bd7d1ea712d571/Pillow-7.2.0-cp38-cp38-win_amd64.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 3.2 MB/s
Requirement already satisfied: future in c:\users\nile-ssd\envs\pytorch385\lib\site-packages (from torch==1.6.0->torchvision==0.7.0+cpu) (0.18.2)
Installing collected packages: pillow, torchvision
Successfully installed pillow-7.2.0 torchvision-0.7.0+cpu
(pytorch385) F:\pytorch>python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
依赖包会自动安装,无需单独安装!
参考:
https://blog.youkuaiyun.com/qq_38161040/article/details/88062405
https://www.cnblogs.com/baowang/p/12499279.html
https://www.cnblogs.com/baowang/p/12499279.html
https://blog.youkuaiyun.com/qq_35722520/article/details/104103300