简体   繁体   English

在 ubuntu16.04 中安装 TensorFlow 时出现问题

[英]Problem installing TensorFlow in ubuntu16.04

I will try to be as much detailed as possible.我会尽量详细。 I am currently in need to use TensorFlow in Pyhton.我目前需要在 Pyhton 中使用 TensorFlow。

  1. My PC runs in Ubuntu, and my ubuntu version is this:我的电脑在 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. If I type python in terminal, I get:如果我在终端中输入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. >>>

So my default python version is Python 2.7.12所以我默认的 python 版本是 Python 2.7.12

  1. I have installed pyhton3.5 following this instrucions and python3.9 following this page .我已经按照这个指令安装了 pyhton3.5,在这个页面之后安装了 python3.9。 While installing, both sets of instructions run (kind of) OK.安装时,两组指令都运行(有点)OK。

  2. If I type $ ll /usr/bin/python* I get:如果我输入$ 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*

So it looks like I have many Pyhton versions installed.所以看起来我安装了很多 Pyhton 版本。 I can run them by typing:我可以通过键入以下内容来运行它们:

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

So it looks that they are there (just not as default.) and they work.所以看起来他们在那里(只是不是默认的。)并且他们工作。

  1. Now, when installing tensorflow, as per these instructions , I get:现在,在安装 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. My pip version is:我的 pip 版本是:

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

7. And finally, my problem is that when trying to run tensorflow in pyhton I get this: 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
    >>>

No matter in which python I run it.无论我在哪个 python 中运行它。 I get the same.我也一样。

  • What am I doing wrong?我究竟做错了什么?
  • Do I just have to change something in the PATH of my system?我只需要更改系统路径中的某些内容吗?
  • What do I change?我要改变什么?
  • How do I do it?我该怎么做? I am really not a tech person and I get lost easily when things like "path" and stuff get in the middle.我真的不是技术人员,当“路径”之类的东西进入中间时,我很容易迷失方向。 If anyone can help me it would be awesome, and I will be grateful.如果有人可以帮助我,那就太好了,我将不胜感激。

Extra relevant data:额外的相关数据:

$ 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: 

So actually, it seems that tensorflow is, at least, installed.所以实际上,似乎至少安装了 tensorflow。

And also tried this, from here , with no success:从这里尝试了这个,但没有成功:

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

I think, you can change default python3 for your system via update-alternatives我认为,您可以通过update-alternatives更改系统的默认 python3

more information here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM