簡體   English   中英

在 ubuntu16.04 中安裝 TensorFlow 時出現問題

[英]Problem installing TensorFlow in ubuntu16.04

我會盡量詳細。 我目前需要在 Pyhton 中使用 TensorFlow。

  1. 我的電腦在 Ubuntu 中運行,我的 ubuntu 版本是這樣的:

     $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial
  2. 如果我在終端中輸入python ,我會得到:

     $ python Python 2.7.12 (default, Mar 1 2021, 11:38:31) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>

所以我默認的 python 版本是 Python 2.7.12

  1. 我已經按照這個指令安裝了 pyhton3.5,在這個頁面之后安裝了 python3.9。 安裝時,兩組指令都運行(有點)OK。

  2. 如果我輸入$ ll /usr/bin/python*我得到:

     $ ll /usr/bin/python* lrwxrwxrwx 1 root root 9 nov 23 2017 /usr/bin/python -> python2.7* lrwxrwxrwx 1 root root 9 nov 23 2017 /usr/bin/python2 -> python2.7* -rwxr-xr-x 1 root root 3492624 mar 1 17:47 /usr/bin/python2.7* lrwxrwxrwx 1 root root 33 mar 1 17:47 /usr/bin/python2.7-config -> x86_64-linux- gnu-python2.7-config* lrwxrwxrwx 1 root root 16 nov 23 2017 /usr/bin/python2-config -> python2.7-config* -rwxr-xr-x 1 root root 306 oct 23 2015 /usr/bin/python2-futurize* -rwxr-xr-x 1 root root 310 oct 23 2015 /usr/bin/python2-pasteurize* -rwxr-xr-x 1 root root 151 nov 23 2015 /usr/bin/python2-pbr* lrwxrwxrwx 1 root root 9 sep 13 2017 /usr/bin/python3 -> python3.5* -rwxr-xr-x 2 root root 4456208 ene 26 15:48 /usr/bin/python3.5* -rwxr-xr-x 2 root root 4456208 ene 26 15:48 /usr/bin/python3.5m* -rwxr-xr-x 2 root root 4604496 may 7 2019 /usr/bin/python3.6* -rwxr-xr-x 2 root root 4604496 may 7 2019 /usr/bin/python3.6m* -rwxr-xr-x 1 root root 306 oct 23 2015 /usr/bin/python3-futurize* lrwxrwxrwx 1 root root 10 sep 13 2017 /usr/bin/python3m -> python3.5m* -rwxr-xr-x 1 root root 310 oct 23 2015 /usr/bin/python3-pasteurize* -rwxr-xr-x 1 root root 152 nov 23 2015 /usr/bin/python3-pbr* lrwxrwxrwx 1 root root 16 nov 23 2017 /usr/bin/python-config -> python2.7-config* lrwxrwxrwx 1 root root 58 mar 25 2016 /usr/bin/pythontex ->../share/texlive/texmf-dist/scripts/pythontex/pythontex.py* -rwxr-xr-x 1 root root 306 mar 25 2016 /usr/bin/pythontex3*

所以看起來我安裝了很多 Pyhton 版本。 我可以通過鍵入以下內容來運行它們:

    $ python3.5
    Python 3.5.2 (default, Jan 26 2021, 13:30:48) 
    [GCC 5.4.0 20160609] on Linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    [8]+  Detenido                python3.5
    
    $ python3.9
    Python 3.9.0 (default, Mar 31 2021, 09:57:03) 
    [GCC 5.4.0 20160609] on Linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

所以看起來他們在那里(只是不是默認的。)並且他們工作。

  1. 現在,在安裝 tensorflow 時,按照這些說明,我得到:

     $ sudo pip install tensorflow-cpu DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. WARNING: The directory '/home/myname/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. .... ....
  2. 我的 pip 版本是:

     $ pip --version pip 20.3.4 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

7. 最后,我的問題是,當試圖在 pyhton 中運行 tensorflow 時,我得到了這個:

    $ python
    Python 2.7.12 (default, Mar  1 2021, 11:38:31) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named tensorflow
    >>>

無論我在哪個 python 中運行它。 我也一樣。

  • 我究竟做錯了什么?
  • 我只需要更改系統路徑中的某些內容嗎?
  • 我要改變什么?
  • 我該怎么做? 我真的不是技術人員,當“路徑”之類的東西進入中間時,我很容易迷失方向。 如果有人可以幫助我,那就太好了,我將不勝感激。

額外的相關數據:

$ pip show tensorflow
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Name: tensorflow
Version: 2.3.1
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /home/myname/.local/lib/python3.5/site-packages
Requires: wrapt, grpcio, keras-preprocessing, numpy, tensorflow-estimator, opt-einsum, six, wheel, absl-py, h5py, protobuf, tensorboard, gast, astunparse, google-pasta, termcolor
Required-by: 

所以實際上,似乎至少安裝了 tensorflow。

從這里嘗試了這個,但沒有成功:

$ pip install tensorflow --ignore-installed --user
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
....
....
....
....
  WARNING: The script chardetect is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts easy_install and easy_install-3.5 are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pyrsa-decrypt, pyrsa-encrypt, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script wheel is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts f2py, f2py3 and f2py3.5 are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script markdown_py is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script google-oauthlib-tool is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script tensorboard is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts estimator_ckpt_converter, saved_model_cli, tensorboard, tf_upgrade_v2, tflite_convert, toco and toco_from_protos are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
....
....

我認為,您可以通過update-alternatives更改系統的默認 python3

更多信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM