https://www.python.org/downloads/windows/
下载3.5.4版本,目前tensorflow不支持3.6以上版本,以下就是因为安装了3.7版本,导致tensorflow不成功的案例。
安装成功后,在PC输入cmd,调出命令窗口,执行python,如下
https://pypi.org/project/tensorflow/
下载python-3.5.4-amd64版本,根据windows下载对应的版本,但不要用3.7版本,不然会出现使用3.7版本,导致1.4.2的错误。
步骤如下:
1)安装CUDA
https://developer.nvidia.com/cuda-toolkit-archive
安装完成后,执行下nvcc -V,有版本号输出,说明成功了
2)安装 cuDNN
https://developer.nvidia.com/cudnn
这个在先注册NVIDIA账号,并填写相关资料才可以下载。。。
下载完成后,设置对应的环境变量
C:\Users\Administrator>pip install tensorflow ## 默认下载最新版本,这边是1.11.0
C:\Users\Administrator>pip install tensorflow-gpu
C:\Users\Administrator>pip install numpy --upgrade
C:\Users\Administrator>pip install matplotlib --upgrade
C:\Users\Administrator>pip install jupyter --upgrade
C:\Users\Administrator>pip install scikit-image --upgrade
C:\Users\Administrator>pip install nltk --upgrade
C:\Users\Administrator>pip install keras --upgrade
C:\Users\Administrator>pip install git+https://github.com/tflearn/tflearn.git
import tensorflow as tf
C:\Users\Administrator>pip install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the ‘python -m pip install --upgrade pip’ command.
C:\Users\Administrator>pip install tensorflow
Collecting tensorflow
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
after connection broken by ‘ConnectTimeoutError(
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
/>>> import tensorflow as tf
Traceback (most recent call last):
File “D:\Program Files\lib\site-packages\numpy\core_init_.py”, line 16, in
from . import multiarray
ImportError: cannot import name ‘multiarray’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “D:\Program Files\lib\site-packages\tensorflow_init_.py”, line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File “D:\Program Files\lib\site-packages\tensorflow\python_init_.py”, line 47, in
import numpy as np
File “D:\Program Files\lib\site-packages\numpy_init_.py”, line 142, in
from . import add_newdocs
File “D:\Program Files\lib\site-packages\numpy\add_newdocs.py”, line 13, in
from numpy.lib import add_newdoc
File “D:\Program Files\lib\site-packages\numpy\lib_init_.py”, line 8, in
from .type_check import *
File “D:\Program Files\lib\site-packages\numpy\lib\type_check.py”, line 11, in
import numpy.core.numeric as nx
File "D:\Program Files\lib\site-packages\numpy\core_init.py", line 26, in
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you’re working with a numpy git repo, try git clean -xdf
(removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name ‘multiarray’
/>>> import tensorflow as tf
Traceback (most recent call last):
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
_mod = imp.load_module(’_pywrap_tensorflow_internal’, fp, pathname, description)
File “D:\Program Files\lib\imp.py”, line 243, in load_module
return load_dynamic(name, filename, file)
File “D:\Program Files\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 “”, line 1, in
File “D:\Program Files\lib\site-packages\tensorflow_init_.py”, line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File “D:\Program Files\lib\site-packages\tensorflow\python_init_.py”, line 49, in
from tensorflow.python import pywrap_tensorflow
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File “D:\Program Files\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
_mod = imp.load_module(’_pywrap_tensorflow_internal’, fp, pathname, description)
File “D:\Program Files\lib\imp.py”, line 243, in load_module
return load_dynamic(name, filename, file)
File “D:\Program Files\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/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
在python3.xx里面,用urllib.request代替urllib2,另外python3之后,不能再用,print html
import urllib2
req = urllib2.Request(link, None, self.headers)
resp = urllib2.urlopen(req, None, timeout)
print(html)
更改为
import urllib.request
resp = urllib.request.urlopen("www.baidu.com")
html = resp.read()
print(html)
在python3.xx里面,使用importlib来定义reload,同时都是utf-8格式,所以不用setdefaultencoding了
reload(sys)
sys.setdefaultencoding("utf-8")
更改为
import importlib
importlib.reload(sys)