http://c.biancheng.net/view/1881.html
https://blog.csdn.net/weixin_42555985/article/details/104182699
系統:64位win10
1.清華鏡像站安裝Anaconda3-4.3.0-Windows-x86_64.exe
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
安裝成功驗證:conda --version
2.安裝完執行python
C:\Users\XXX>python
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
3.anaconda源修改爲國內鏡像源,否則進行第四步時會出錯(通過修改用戶目錄下的 .condarc
文件)
https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
文件內容修改爲:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
4.創建環境
C:\Users\XXX>conda create --name tensorflow python=3.6
Fetching package metadata .............
Solving package specifications: .
Warning: 4 possible package resolutions (only showing differing packages):
- defaults::vc-14.1-h21ff451_4, defaults::wincertstore-0.2-py36_0
- defaults::vc-14.1-h0510ff6_4, defaults::wincertstore-0.2-py36_0
- defaults::vc-14.1-h21ff451_4, defaults::wincertstore-0.2-py36h7fe50ca_0
- defaults::vc-14.1-h0510ff6_4, defaults::wincertstore-0.2-py36h7fe50ca_0
Package plan for installation in environment D:\anaconda\envs\tensorflow:
The following NEW packages will be INSTALLED:
certifi: 2019.11.28-py36_0 defaults
pip: 20.0.2-py36_1 defaults
python: 3.6.10-h9f7ef89_0 defaults
setuptools: 45.2.0-py36_0 defaults
sqlite: 3.31.1-he774522_0 defaults
vc: 14.1-h21ff451_4 defaults
vs2015_runtime: 14.16.27012-hf0eaf9b_1 defaults
wheel: 0.34.2-py36_0 defaults
wincertstore: 0.2-py36_0 defaults
Proceed ([y]/n)? y
vs2015_runtime 100% |###############################| Time: 0:00:01 2.49 MB/s
vc-14.1-h21ff4 100% |###############################| Time: 0:00:00 1.54 MB/s
sqlite-3.31.1- 100% |###############################| Time: 0:00:00 1.45 MB/s
python-3.6.10- 100% |###############################| Time: 0:00:15 1.36 MB/s
certifi-2019.1 100% |###############################| Time: 0:00:00 5.34 MB/s
wincertstore-0 100% |###############################| Time: 0:00:00 0.00 B/s
setuptools-45. 100% |###############################| Time: 0:00:00 5.06 MB/s
wheel-0.34.2-p 100% |###############################| Time: 0:00:00 5.98 MB/s
pip-20.0.2-py3 100% |###############################| Time: 0:00:01 1.79 MB/s
#
# To activate this environment, use:
# > activate tensorflow
#
# To deactivate this environment, use:
# > deactivate tensorflow
#
# * for power-users using bash, you must source
#
5.激活
(tensorflow) C:\Users\XXX>activate tensorflow
(tensorflow) C:\Users\XXX>python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
6.安裝tensorflow
https://blog.csdn.net/weixin_38109583/article/details/93376954
直接pip install tensorflow速度太慢,改爲python -m pip install tensorflow==2.0 -i https://pypi.douban.com/simple
不指定tensorflow版本,版本太高可能會出錯
(tensorflow) C:\Users\XXX>python -m pip install tensorflow==2.0 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting tensorflow==2.0
Downloading https://pypi.doubanio.com/packages/d3/af/296748d4c8d8987423231b93aecce5ab5952f6f2243cb6cedb88dd425397/tensorflow-2.0.0-cp36-cp36m-win_amd64.whl (48.1 MB)
|████████████████████████████████| 48.1 MB 731 kB/s
Requirement already satisfied: absl-py>=0.7.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (0.9.0)
Requirement already satisfied: opt-einsum>=2.3.2 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (3.1.0)
Requirement already satisfied: astor>=0.6.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (0.8.1)
Requirement already satisfied: keras-applications>=1.0.8 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.0.8)
Requirement already satisfied: six>=1.10.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.14.0)
Requirement already satisfied: grpcio>=1.8.6 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.27.1)
Requirement already satisfied: keras-preprocessing>=1.0.5 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.1.0)
Requirement already satisfied: numpy<2.0,>=1.16.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.18.1)
Requirement already satisfied: protobuf>=3.6.1 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (3.11.3)
Collecting tensorboard<2.1.0,>=2.0.0
Downloading https://pypi.doubanio.com/packages/76/54/99b9d5d52d5cb732f099baaaf7740403e83fe6b0cedde940fabd2b13d75a/tensorboard-2.0.2-py3-none-any.whl (3.8 MB)
|████████████████████████████████| 3.8 MB 819 kB/s
Requirement already satisfied: termcolor>=1.1.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.1.0)
Requirement already satisfied: gast==0.2.2 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (0.2.2)
Requirement already satisfied: wrapt>=1.11.1 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (1.11.2)
Collecting tensorflow-estimator<2.1.0,>=2.0.0
Downloading https://pypi.doubanio.com/packages/fc/08/8b927337b7019c374719145d1dceba21a8bb909b93b1ad6f8fb7d22c1ca1/tensorflow_estimator-2.0.1-py2.py3-none-any.whl (449 kB)
|████████████████████████████████| 449 kB 297 kB/s
Requirement already satisfied: wheel>=0.26 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (0.34.2)
Requirement already satisfied: google-pasta>=0.1.6 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorflow==2.0) (0.1.8)
Requirement already satisfied: h5py in d:\anaconda\envs\tensorflow\lib\site-packages (from keras-applications>=1.0.8->tensorflow==2.0) (2.10.0)
Requirement already satisfied: setuptools in d:\anaconda\envs\tensorflow\lib\site-packages (from protobuf>=3.6.1->tensorflow==2.0) (45.2.0.post20200210)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.4.1)
Requirement already satisfied: google-auth<2,>=1.6.3 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.11.1)
Requirement already satisfied: requests<3,>=2.21.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2.22.0)
Requirement already satisfied: markdown>=2.6.8 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.2.1)
Requirement already satisfied: werkzeug>=0.11.15 in d:\anaconda\envs\tensorflow\lib\site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.0.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.3.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in d:\anaconda\envs\tensorflow\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.2.8)
Requirement already satisfied: rsa<4.1,>=3.1.4 in d:\anaconda\envs\tensorflow\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (4.0)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in d:\anaconda\envs\tensorflow\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in d:\anaconda\envs\tensorflow\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in d:\anaconda\envs\tensorflow\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.25.8)
Requirement already satisfied: idna<2.9,>=2.5 in d:\anaconda\envs\tensorflow\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2.8)
Requirement already satisfied: oauthlib>=3.0.0 in d:\anaconda\envs\tensorflow\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.1.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in d:\anaconda\envs\tensorflow\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.4.8)
Installing collected packages: tensorboard, tensorflow-estimator, tensorflow
Attempting uninstall: tensorboard
Found existing installation: tensorboard 2.1.0
Uninstalling tensorboard-2.1.0:
Successfully uninstalled tensorboard-2.1.0
Attempting uninstall: tensorflow-estimator
Found existing installation: tensorflow-estimator 2.1.0
Uninstalling tensorflow-estimator-2.1.0:
Successfully uninstalled tensorflow-estimator-2.1.0
Successfully installed tensorboard-2.0.2 tensorflow-2.0.0 tensorflow-estimator-2.0.1
7.測試
(tensorflow) C:\Users\XXX>python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
8.安裝過程中的一些報錯:第三步,第六步
a.(tensorflow) C:\Users\XXX>pip install --ignore-installed --upgrade tensorflow
Collecting tensorflow
Downloading tensorflow-2.1.0-cp36-cp36m-win_amd64.whl (355.9 MB)
| | 81 kB 15 kB/s eta 6:16:41ERROR: Exception:
Traceback (most recent call last):
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\urllib3\response.py", line 425, in _error_catcher
yield
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\urllib3\response.py", line 507, in read
data = self._fp.read(amt) if not fp_closed else b""
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "D:\anaconda\envs\tensorflow\lib\http\client.py", line 459, in read
n = self.readinto(b)
File "D:\anaconda\envs\tensorflow\lib\http\client.py", line 503, in readinto
n = self.fp.readinto(b)
File "D:\anaconda\envs\tensorflow\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "D:\anaconda\envs\tensorflow\lib\ssl.py", line 1012, in recv_into
return self.read(nbytes, buffer)
File "D:\anaconda\envs\tensorflow\lib\ssl.py", line 874, in read
return self._sslobj.read(len, buffer)
File "D:\anaconda\envs\tensorflow\lib\ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\cli\base_command.py", line 186, in _main
status = self.run(options, args)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\commands\install.py", line 331, in run
resolver.resolve(requirement_set)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\legacy_resolve.py", line 177, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\legacy_resolve.py", line 333, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\legacy_resolve.py", line 282, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\operations\prepare.py", line 482, in prepare_linked_requirement
hashes=hashes,
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\operations\prepare.py", line 287, in unpack_url
hashes=hashes,
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\operations\prepare.py", line 159, in unpack_http_url
link, downloader, temp_dir.path, hashes
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\operations\prepare.py", line 303, in _download_http_url
for chunk in download.chunks:
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\utils\ui.py", line 160, in iter
for x in it:
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_internal\network\utils.py", line 39, in response_chunks
decode_content=False,
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\urllib3\response.py", line 564, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\urllib3\response.py", line 529, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "D:\anaconda\envs\tensorflow\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "D:\anaconda\envs\tensorflow\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
b.未指定tensorflow版本python -m pip install tensorflow -i https://pypi.douban.com/simple
(tensorflow) C:\Users\XXX>python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\anaconda\envs\tensorflow\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\anaconda\envs\tensorflow\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模塊。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
from tensorflow_core import *
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "D:\anaconda\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\anaconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\anaconda\envs\tensorflow\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\anaconda\envs\tensorflow\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模塊。
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.