python安装

python安装

  • 1. 环境搭建
    • 1.1 python下载路径:
    • 1.2 python windowns版本安装过程
    • 1.3 tensorflow
    • 1.4 Question
      • 1.4.1 No matching distribution found for tensorflow
      • 1.4.2 Retry(total=4, connect=None, read=None, redirect=None, status=None)
      • 1.4.3 cannot import name 'multiarray'
      • 1.4.4 Failed to load the native TensorFlow runtime
      • 1.4.5 ImportError: No module named 'urllib2'
      • 1.4.6 name 'reload' is not defined


1. 环境搭建

1.1 python下载路径:

https://www.python.org/downloads/windows/
下载3.5.4版本,目前tensorflow不支持3.6以上版本,以下就是因为安装了3.7版本,导致tensorflow不成功的案例。

1.2 python windowns版本安装过程

python安装_第1张图片
python安装_第2张图片
python安装_第3张图片
python安装_第4张图片
安装成功后,在PC输入cmd,调出命令窗口,执行python,如下
python安装_第5张图片

1.3 tensorflow

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
python安装_第6张图片
安装完成后,执行下nvcc -V,有版本号输出,说明成功了
python安装_第7张图片
2)安装 cuDNN
https://developer.nvidia.com/cudnn
这个在先注册NVIDIA账号,并填写相关资料才可以下载。。。
python安装_第8张图片
下载完成后,设置对应的环境变量
python安装_第9张图片
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

1.4 Question

1.4.1 No matching distribution found for tensorflow

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.

  • solution
    C:\Users\Administrator>python -m pip install --upgrade pip

1.4.2 Retry(total=4, connect=None, read=None, redirect=None, status=None)

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(, ‘Connection to pypi.orgtimed out. (connect timeout=15)’)’: /simple/tensorflow/
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

  • solution
    C:\Users\Administrator>pip install requests -i http://pypi.douban.com/simple/ –
    trusted-host pypi.douban.com
    C:\Users\Administrator>pip install selectivesearch -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
    谁操作后,也不是行,后面查了下,原本目前tensorflow还不支持3.7的版本,后面又下载了3.5.4版本的,先把之前的python版本,在控制面板–>程序与功能中把之前安装的版本给卸载掉,重新系统后,再重新安装3.5.4python,就可以了执行pip install tensorflow了。。。
    最后成功log为:
    C:\Users\Administrator>pip install tensorflow
    Collecting tensorflow
    Using cached https://files.pythonhosted.org/packages/af/5b/695e2e66feb27742a78
    f938d8369cc874b5fc7082193c3352c9db599af01/tensorflow-1.11.0-cp35-cp35m-win_amd64
    .whl
    … … … . … … . … … … … . … … … . … … … … …
    Successfully installed absl-py-0.6.1 astor-0.7.1 gast-0.2.0 grpcio-1.16.0 h5py-2
    .8.0 keras-applications-1.0.6 keras-preprocessing-1.0.5 markdown-3.0.1 protobuf-
    3.6.1 tensorboard-1.11.0 tensorflow-1.11.0 termcolor-1.1.0 werkzeug-0.14.1 wheel
    -0.32.2
    C:\Users\Administrator>

1.4.3 cannot import name ‘multiarray’

/>>> 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’

  • solution
    C:\Users\Administrator>pip uninstall numpy
    C:\Users\Administrator>pip install numpy

1.4.4 Failed to load the native TensorFlow runtime

/>>> 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.

  • solution
    下载Microsoft Visual C++ 2015安装即可

1.4.5 ImportError: No module named ‘urllib2’

在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)

1.4.6 name ‘reload’ is not defined

在python3.xx里面,使用importlib来定义reload,同时都是utf-8格式,所以不用setdefaultencoding了

reload(sys)
sys.setdefaultencoding("utf-8")

更改为

import importlib
importlib.reload(sys)

你可能感兴趣的:(python)