pytorch入门----window+anaconda+pip安装

参考教程:

安装 https://blog.csdn.net/qq_39245207/article/details/84030550


(base) C:\Users\PC>pip3 install https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp37-cp37m-win_amd64.whl
Collecting torchvision==0.3.0 from https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp37-cp37m-win_amd64.whl
  Downloading https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp37-cp37m-win_amd64.whl (232kB)
    100% |████████████████████████████████| 235kB 64kB/s
Collecting six (from torchvision==0.3.0)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting torch>=1.1.0 (from torchvision==0.3.0)
  Could not find a version that satisfies the requirement torch>=1.1.0 (from torchvision==0.3.0) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
No matching distribution found for torch>=1.1.0 (from torchvision==0.3.0)
You are using pip version 19.0.3, however version 19.2.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(base) C:\Users\PC>pip3 install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-win_amd64.whl
Collecting torch==1.1.0 from https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-win_amd64.whl
  Downloading https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-win_amd64.whl (99.6MB)
    100% |████████████████████████████████| 99.6MB 191kB/s
Collecting numpy (from torch==1.1.0)
  Downloading https://files.pythonhosted.org/packages/26/26/73ba03b2206371cdef62afebb877e9ba90a1f0dc3d9de22680a3970f5a50/numpy-1.17.0-cp37-cp37m-win_amd64.whl (12.8MB)
    100% |████████████████████████████████| 12.8MB 26kB/s
Installing collected packages: numpy, torch
Successfully installed numpy-1.17.0 torch-1.1.0
You are using pip version 19.0.3, however version 19.2.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

测试一下:

(base) C:\Users\PC>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>> exit()

(base) C:\Users\PC>pip list
Package                            Version
---------------------------------- --------
alabaster                          0.7.12
anaconda-client                    1.7.2
anaconda-navigator                 1.9.7
anaconda-project                   0.8.2
asn1crypto                         0.24.0
astroid                            2.2.5
astropy                            3.1.2
atomicwrites                       1.3.0
attrs                              19.1.0
Babel                              2.6.0
backcall                           0.1.0
backports.os                       0.1.1
backports.shutil-get-terminal-size 1.0.0
beautifulsoup4                     4.7.1
bitarray                           0.8.3
bkcharts                           0.2
bleach                             3.1.0
bokeh                              1.0.4
boto                               2.49.0
Bottleneck                         1.2.1
certifi                            2019.3.9
cffi                               1.12.2
chardet                            3.0.4
Click                              7.0
cloudpickle                        0.8.0
clyent                             1.2.2
colorama                           0.4.1
comtypes                           1.1.7
conda                              4.6.14
conda-build                        3.17.8
conda-verify                       3.1.1
contextlib2                        0.5.5
cryptography                       2.6.1
cycler                             0.10.0
Cython                             0.29.6
cytoolz                            0.9.0.1
dask                               1.1.4
decorator                          4.4.0
defusedxml                         0.5.0
distributed                        1.26.0
docutils                           0.14
entrypoints                        0.3
et-xmlfile                         1.0.1
fastcache                          1.0.2
filelock                           3.0.10
Flask                              1.0.2
future                             0.17.1
gevent                             1.4.0
glob2                              0.6
greenlet                           0.4.15
h5py                               2.8.0
heapdict                           1.0.0
html5lib                           1.0.1
idna                               2.8
imageio                            2.5.0
imagesize                          1.1.0
importlib-metadata                 0.0.0
ipykernel                          5.1.0
ipython                            7.4.0
ipython-genutils                   0.2.0
ipywidgets                         7.4.2
isort                              4.3.16
itsdangerous                       1.1.0
jdcal                              1.4
jedi                               0.13.3
Jinja2                             2.10
jsonschema                         3.0.1
jupyter                            1.0.0
jupyter-client                     5.2.4
jupyter-console                    6.0.0
jupyter-core                       4.4.0
jupyterlab                         0.35.4
jupyterlab-server                  0.2.0
keyring                            18.0.0
kiwisolver                         1.0.1
lazy-object-proxy                  1.3.1
libarchive-c                       2.8
llvmlite                           0.28.0
locket                             0.2.0
lxml                               4.3.2
MarkupSafe                         1.1.1
matplotlib                         3.0.3
mccabe                             0.6.1
menuinst                           1.4.16
mistune                            0.8.4
mkl-fft                            1.0.10
mkl-random                         1.0.2
more-itertools                     6.0.0
mpmath                             1.1.0
msgpack                            0.6.1
multipledispatch                   0.6.0
navigator-updater                  0.2.1
nbconvert                          5.4.1
nbformat                           4.4.0
networkx                           2.2
nltk                               3.4
nose                               1.3.7
notebook                           5.7.8
numba                              0.43.1
numexpr                            2.6.9
numpy                              1.16.2
numpydoc                           0.8.0
olefile                            0.46
openpyxl                           2.6.1
packaging                          19.0
pandas                             0.24.2
pandocfilters                      1.4.2
parso                              0.3.4
partd                              0.3.10
path.py                            11.5.0
pathlib2                           2.3.3
patsy                              0.5.1
pep8                               1.7.1
pickleshare                        0.7.5
Pillow                             5.4.1
pip                                19.0.3
pkginfo                            1.5.0.1
pluggy                             0.9.0
ply                                3.11
prometheus-client                  0.6.0
prompt-toolkit                     2.0.9
psutil                             5.6.1
py                                 1.8.0
pycodestyle                        2.5.0
pycosat                            0.6.3
pycparser                          2.19
pycrypto                           2.6.1
pycurl                             7.43.0.2
pyflakes                           2.1.1
Pygments                           2.3.1
pylint                             2.3.1
pyodbc                             4.0.26
pyOpenSSL                          19.0.0
pyparsing                          2.3.1
pyreadline                         2.1
pyrsistent                         0.14.11
PySocks                            1.6.8
pytest                             4.3.1
pytest-arraydiff                   0.3
pytest-astropy                     0.5.0
pytest-doctestplus                 0.3.0
pytest-openfiles                   0.3.2
pytest-remotedata                  0.3.1
python-dateutil                    2.8.0
pytz                               2018.9
PyWavelets                         1.0.2
pywin32                            223
pywinpty                           0.5.5
PyYAML                             5.1
pyzmq                              18.0.0
QtAwesome                          0.5.7
qtconsole                          4.4.3
QtPy                               1.7.0
requests                           2.21.0
rope                               0.12.0
ruamel-yaml                        0.15.46
scikit-image                       0.14.2
scikit-learn                       0.20.3
scipy                              1.2.1
seaborn                            0.9.0
Send2Trash                         1.5.0
setuptools                         40.8.0
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
six                                1.12.0
snowballstemmer                    1.2.1
sortedcollections                  1.1.2
sortedcontainers                   2.1.0
soupsieve                          1.8
Sphinx                             1.8.5
sphinxcontrib-websupport           1.1.0
spyder                             3.3.3
spyder-kernels                     0.4.2
SQLAlchemy                         1.3.1
statsmodels                        0.9.0
sympy                              1.3
tables                             3.4.4
tblib                              1.3.2
terminado                          0.8.1
testpath                           0.4.2
toolz                              0.9.0
tornado                            6.0.2
tqdm                               4.31.1
traitlets                          4.3.2
unicodecsv                         0.14.1
urllib3                            1.24.1
wcwidth                            0.1.7
webencodings                       0.5.1
Werkzeug                           0.14.1
wheel                              0.33.1
widgetsnbextension                 3.4.2
win-inet-pton                      1.1.0
win-unicode-console                0.5
wincertstore                       0.2
wrapt                              1.11.1
xlrd                               1.2.0
XlsxWriter                         1.1.5
xlwings                            0.15.4
xlwt                               1.3.0
zict                               0.1.4
zipp                               0.3.3

(base) C:\Users\PC>pip3 list
Package    Version
---------- -------
numpy      1.17.0
pip        19.0.3
setuptools 40.8.0
torch      1.1.0

通过pip3安装的torch已经安装好了,但是pip目录中不包含torch

查阅了一下:https://blog.csdn.net/lvsehaiyang1993/article/details/80596513

简单来说pip和pip3是一样的,只是为了区别python2和python3之间的调用,避免冲突而进行的设定。

安装了python3之后,库里面既会有pip3也会有pip 
1. 使用pip install XXX 
新安装的库会放在这个目录下面 
python2.7/site-packages 
2. 使用pip3 install XXX 
新安装的库会放在这个目录下面 
python3.6/site-packages 
如果使用python3执行程序,那么就不能import python2.7/site-packages中的库 

但是我没有py27,

随机引用一个pip库:

(base) C:\Users\PC>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import zict
>>>

证明python3.7正在使用pip安装的库,查看一下库的位置:

(base) C:\Users\PC>pip show zict
Name: zict
Version: 0.1.4
Summary: Mutable mapping tools
Home-page: http://zict.readthedocs.io/en/latest/
Author: None
Author-email: None
License: BSD
Location: d:\anaconda3\lib\site-packages
Requires: heapdict
Required-by: distributed

(base) C:\Users\PC>pip3 show torch
Name: torch
Version: 1.1.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Location: d:\py\lib\site-packages
Requires: numpy
Required-by:

pip和pip3安装目录是不一样的,在base环境中的python只能使用anaconda目录下的库也不意外了,直接简单粗暴地找到这个目录copy进pip库中

在此查阅

(base) C:\Users\PC>pip list
Package                            Version
---------------------------------- --------
alabaster                          0.7.12
anaconda-client                    1.7.2
anaconda-navigator                 1.9.7
anaconda-project                   0.8.2
asn1crypto                         0.24.0
……
testpath                           0.4.2
toolz                              0.9.0
torch                              1.1.0
tornado                            6.0.2
tqdm                               4.31.1
traitlets                          4.3.2
unicodecsv                         0.14.1
urllib3                            1.24.1
wcwidth                            0.1.7
webencodings                       0.5.1
Werkzeug                           0.14.1
……

zipp                               0.3.3

torch出现,启动python测试一下 :

>>> import torch
>>> torch.__version__
'1.1.0'
>>>

说明已经安装好了。

2019/09/02更新 

在python中测试时出现错误:No module named 'numpy.core._multiarray_umath'

只需要更新pip升级版本就可以解决了

参考链接:https://blog.csdn.net/a6840231/article/details/88256524

发布了46 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_36808245/article/details/98737723
今日推荐