【问题标题】:How to install tensorflow?如何安装张量流?
【发布时间】:2020-02-07 20:59:32
【问题描述】:

我在计算机上安装 TensorFlow 时遇到了一些困难。

我的操作系统:Windows 8

我的 Python 版本:3.7(64 位)

我使用 pip install TensorFlow

https://www.tensorflow.org/install/pip

我应该将它的命令复制到 cmd 吗?或者我应该相应地更改它们的一些细节?

例如:

我尝试运行代码:

pip3 install -U pip virtualenv

这是我得到的:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\A>virtualenv --system-site-packages -p python3 ./venv
The path python3 (from --python=python3) does not exist

“路径不存在”是什么意思?我尝试更改“python3”。到“python3.7 .”,但还是不行。

即使第一个命令没有成功,我的电脑上似乎已经安装了 pip、python 和 virtualenv。

这是我尝试下载 Tensorflow 时遇到的问题:

我尝试运行代码:

pip install --upgrade tensorflow

这是错误:

C:\Users\A>.\venv\Scripts\activate
The system cannot find the path specified.

C:\Users\A>pip install --upgrade pip
Requirement already up-to-date: pip in c:\users\a\appdata\local\programs\python\
python37\lib\site-packages (20.0.2)

C:\Users\A>
C:\Users\A>pip list  # show packages installed within the virtual environment
Package    Version
---------- -------
pip        20.0.2
setuptools 45.1.0
virtualenv 16.7.9
wheel      0.34.2

C:\Users\A>pip install --upgrade tensorflow
Collecting tensorflow
  Downloading tensorflow-2.1.0-cp37-cp37m-win_amd64.whl (355.8 MB)
     |                                | 788 kB 3.2 kB/s eta 1 day, 6:26:40ERROR:
 Exception:
Traceback (most recent call last):
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_vendor\urllib3\response.py", line 425, in _error_catcher
    yield
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_vendor\urllib3\response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "c:\users\a\appdata\local\programs\python\python37\lib\http\client.py", l
ine 457, in read
    n = self.readinto(b)
  File "c:\users\a\appdata\local\programs\python\python37\lib\http\client.py", l
ine 501, in readinto
    n = self.fp.readinto(b)
  File "c:\users\a\appdata\local\programs\python\python37\lib\socket.py", line 5
89, in readinto
    return self._sock.recv_into(b)
  File "c:\users\a\appdata\local\programs\python\python37\lib\ssl.py", line 1071
, in recv_into
    return self.read(nbytes, buffer)
  File "c:\users\a\appdata\local\programs\python\python37\lib\ssl.py", line 929,
 in read
    return 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 "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\cli\base_command.py", line 186, in _main
    status = self.run(options, args)
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\commands\install.py", line 331, in run
    resolver.resolve(requirement_set)
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\legacy_resolve.py", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\operations\prepare.py", line 482, in prepare_linked_requirement
    hashes=hashes,
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\operations\prepare.py", line 287, in unpack_url
    hashes=hashes,
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\operations\prepare.py", line 159, in unpack_http_url
    link, downloader, temp_dir.path, hashes
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\operations\prepare.py", line 303, in _download_http_url
    for chunk in download.chunks:
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\utils\ui.py", line 160, in iter
    for x in it:
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_internal\network\utils.py", line 39, in response_chunks
    decode_content=False,
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_vendor\urllib3\response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:\users\a\appdata\local\programs\python\python37\lib\site-packages\pip\
_vendor\urllib3\response.py", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "c:\users\a\appdata\local\programs\python\python37\lib\contextlib.py", li
ne 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\users\a\appdata\local\programs\python\python37\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.

C:\Users\A>https://github.com/tensorflow/tensorflow/issues/5949

如何安装 TensorFlow?谢谢!

更新 1:

当我将“python 3”更改为“python”,将“pip3”更改为“pip”时,前几个命令行可以正常工作。

但是,我仍然无法下载 Tensorflow。

这次又下载了一点:

(venv) C:\Users\A> pip install --upgrade tensorflow
Collecting tensorflow
  Downloading tensorflow-2.1.0-cp37-cp37m-win_amd64.whl (355.8 MB)
     |█                               | 8.4 MB 10.0 kB/s eta 9:40:28ERROR: Exce
ption:
Traceback (most recent call last):
  File "c:\users\a\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line
 425, in _error_catcher
    yield
  File "c:\users\a\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line
 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "c:\users\a\venv\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.p
y", line 62, in read
    data = self.__fp.read(amt)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\http\client.py", l
ine 457, in read
    n = self.readinto(b)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\http\client.py", l
ine 501, in readinto
    n = self.fp.readinto(b)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\socket.py", line 5
89, in readinto
    return self._sock.recv_into(b)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\ssl.py", line 1071
, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\ssl.py", line 929,
 in read
    return 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 "c:\users\a\venv\lib\site-packages\pip\_internal\cli\base_command.py", li
ne 186, in _main
    status = self.run(options, args)
  File "c:\users\a\venv\lib\site-packages\pip\_internal\commands\install.py", li
ne 331, in run
    resolver.resolve(requirement_set)
  File "c:\users\a\venv\lib\site-packages\pip\_internal\legacy_resolve.py", line
 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "c:\users\a\venv\lib\site-packages\pip\_internal\legacy_resolve.py", line
 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\a\venv\lib\site-packages\pip\_internal\legacy_resolve.py", line
 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "c:\users\a\venv\lib\site-packages\pip\_internal\operations\prepare.py",
line 482, in prepare_linked_requirement
    hashes=hashes,
  File "c:\users\a\venv\lib\site-packages\pip\_internal\operations\prepare.py",
line 287, in unpack_url
    hashes=hashes,
  File "c:\users\a\venv\lib\site-packages\pip\_internal\operations\prepare.py",
line 159, in unpack_http_url
    link, downloader, temp_dir.path, hashes
  File "c:\users\a\venv\lib\site-packages\pip\_internal\operations\prepare.py",
line 303, in _download_http_url
    for chunk in download.chunks:
  File "c:\users\a\venv\lib\site-packages\pip\_internal\utils\ui.py", line 160,
in iter
    for x in it:
  File "c:\users\a\venv\lib\site-packages\pip\_internal\network\utils.py", line
39, in response_chunks
    decode_content=False,
  File "c:\users\a\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line
 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:\users\a\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line
 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "C:\Users\A\AppData\Local\Programs\Python\Python37\Lib\contextlib.py", li
ne 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\users\a\venv\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.

(venv) C:\Users\A>

更新 2:

我使用了以下命令行:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow

下载了更多内容。

这是新的错误:

ERROR: Could not find a version that satisfies the requirement tensorboard<2.2.0
,>=2.1.0 (from tensorflow) (from versions: 1.6.0rc0, 1.6.0, 1.7.0, 1.8.0, 1.9.0,
 1.10.0, 1.11.0, 1.12.0, 1.12.1, 1.12.2, 1.13.0, 1.13.1, 1.14.0, 1.15.0, 2.0.0,
2.0.1, 2.0.2)
ERROR: No matching distribution found for tensorboard<2.2.0,>=2.1.0 (from tensor
flow)

C:\Users\A>

我需要不同版本的 Tensorflow 吗?

【问题讨论】:

  • 你试过用'python'代替'python3'吗?
  • 这行得通。当我将 'python' 用于 'python3' 和 'pip' 用于 'pip3' 时,前几个命令可以正常工作。
  • 作为 Windows 的建议,通常最好使用 anaconda。
  • 检查这些变通方法以了解您的 Update 2 错误github.com/tensorflow/tensorflow/issues/36380

标签: python tensorflow


【解决方案1】:

使用以下命令在虚拟环境中安装 TensorFlow。

1) 升级 pip3: python3 -m pip install --upgrade pip 2)安装虚拟环境 pip3 安装 virtualenv 3)然后您可以使用python3的完整路径创建一个virtualenv,如下所示: virtualenv -p /home/example_username/opt/python-3.6.2/bin/python3 venv 4)激活虚拟环境 来源 venv/bin/activate 5)安装张量流 pip3 安装张量流

【讨论】:

    【解决方案2】:

    请注意此错误消息。

    raise ReadTimeoutError(self._pool, None, "Read timed out.")
    pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files
    .pythonhosted.org', port=443): Read timed out.
    

    您似乎无法连接到files.pythonhosted.org。您可以先访问此网址:https://pypi.org/project/tensorflow/#files 以向下 tensorflow-2.1.0-cp37-cp37m-win_amd64.whl。然后使用pip install &lt;name&gt;.whl 安装它。

    更多: 如果您在中国,可以使用以下命令安装清华大学的tensorflow。

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
    

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 2021-02-03
      • 2018-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      相关资源
      最近更新 更多