[Python] How to install tensorflow?

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am having some difficulties in installing TensorFlow on my computer.

    My OS: Windows 8

    My Python version: 3.7 (64-bit)

    I used pip install Tensorflow

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

    Should I copy its commands to cmd? Or I should change some details of them accordingly?

    For example:

    I tried running code:

    pip3 install -U pip virtualenv


    Here is what I get:

    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


    What does it mean by "the path does not exist"? I tried changing "python3 ." to "python3.7 .", but it doesn't work out.

    Even tho the first command didn't work out, it seems the pip, python, and virtualenv are installed on my PC.

    Here is the issue I have when I try to download Tensorflow:

    I tried running code:

    pip install --upgrade tensorflow


    This is the error:

    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


    How can I install Tensorflow? Thank you!

    Update 1:

    When I change 'python 3' to 'python', and 'pip3' to 'pip', the first few command lines work out.

    However, I still can't download Tensorflow.

    A bit more has been downloaded this time:

    (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>


    Update 2:

    I used the following command line:

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


    Much more was downloaded.

    Here is the new error:

    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>


    Do I need a different version of Tensorflow?

    Continue reading...

Compartilhe esta Página