Python 尝试安装keras&;Amazon AWS实例上的tensorflow

Python 尝试安装keras&;Amazon AWS实例上的tensorflow,python,r,tensorflow,amazon-ec2,keras,Python,R,Tensorflow,Amazon Ec2,Keras,我在Ubuntu EC2实例上安装keras和tensorflow时遇到了一些问题 我在库中加载并尝试安装keras library(keras) library(tensorflow) install_keras(tensorflow = "gpu") 我得到以下错误: 我还运行了以下命令以及一些其他终端命令,以尝试安装conda和python等 sudo apt install git libpython3.7-dev 我还跟随keras.io网站尝试安装了它。我在服务器上有一个名为/u

我在Ubuntu EC2实例上安装keras和tensorflow时遇到了一些问题

我在库中加载并尝试安装keras

library(keras)
library(tensorflow)
install_keras(tensorflow = "gpu")
我得到以下错误:

我还运行了以下命令以及一些其他终端命令,以尝试安装conda和python等

sudo apt install git libpython3.7-dev
我还跟随keras.io网站尝试安装了它。我在服务器上有一个名为
/usr/bin/python3.6:
的文件夹,但是当我尝试访问它时,我得到一个错误
目录/usr/bin/python3.6:没有这样的文件或目录
。我在服务器的
home
目录下有两个用户帐户(以及两个同名文件夹)
ubuntu
myUsername\u文件夹

/home/myUsername\u文件夹中
我有
.rstudio
文件。(
/home/myUsername\u folder/.rstudio
)和一些数据集。 在
home/ubuntu
文件夹中,我安装了R
/home/ubuntu/R/x86\u 64-pc-linux-gnu-library/3.6
。 在
/
根目录中,我有一些文件夹,如
usr
var
lib64
tmp
bin

我如何告诉R Python位于何处

编辑:

我重新启动RStudio并运行:

> library(keras)
> library(tensorflow)
> install_keras(tensorflow = "gpu")
Using virtual environment '~/.virtualenvs/r-reticulate' ...
/home/myUser/.virtualenvs/r-reticulate/bin/python: No module named pip
Error in strsplit(output, "\\s+")[[1]] : subscript out of bounds
In addition: Warning message:
In system2(python, c("-m", "pip", "--version"), stdout = TRUE) :
  running command ''/home/myUser/.virtualenvs/r-reticulate/bin/python' -m pip --version' had status 1
尝试使用以下方法安装
pip

sudo apt-get install python3-pip

Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (9.0.1-2.3~ubuntu1.18.04.1).
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
我运行了以下程序来安装Anaconda:

wget bash Anaconda3-2019.10-Linux-x86_64.sh

然后跑:

> install_keras(method = c("conda"),
+               conda = "auto", version = "default", tensorflow = "gpu")
ERROR: The install method you used for conda--probably either `pip install conda`
or `easy_install conda`--is not compatible with using conda as an application.
If your intention is to install conda as a standalone application, currently
supported install methods include the Anaconda installer and the miniconda
installer.  You can download the miniconda installer from
https://conda.io/miniconda.html.

Error: Error 1 occurred creating conda environment r-reticulate
编辑:我试过:

wget bash Miniconda3-latest-Linux-x86_64.sh

然后在RStudio

> install_keras(method = c("conda"),
+               conda = "/home/myUser/miniconda3/bin/",
+               version = "default", tensorflow = "gpu")
sh: 1: /home/myuser/miniconda3/bin/: Permission denied
Error: Error 126 occurred creating conda environment r-reticulate
tf_config()
我更改权限:

sudo chmod -R 777 /home/myUser/miniconda3/bin/
并在运行
install_keras(…)
后得到相同的错误

编辑:

我在RStudio跑步

> install_keras(method = c("conda"),
+               conda = "/home/myUser/miniconda3/bin/",
+               version = "default", tensorflow = "gpu")
sh: 1: /home/myuser/miniconda3/bin/: Permission denied
Error: Error 126 occurred creating conda environment r-reticulate
tf_config()
找不到TensorFlow的安装

Python environments searched for 'tensorflow' package:
 /usr/bin/python3.6
 /usr/bin/python3.6
 /usr/bin/python2.7
 /home/myuser/anaconda3/bin/python3.7
 /usr/bin/python3.6
 /home/myuser/miniconda3/bin/python3.7
您可以使用install_TensorFlow()函数安装TensorFlow

install_tensorflow()
错误:找不到/usr/bin/Python的Python环境

我还尝试使用python(“/home/myuser/anaconda3/bin/python3.7”)

编辑

上述问题仍然存在,但我可以运行以下R代码(该代码“有效”):

在这里我得到了这个信息:

/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/myuser/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

2020-01-21 21:49:45.344207: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-01-21 21:49:45.384211: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2400050000 Hz
2020-01-21 21:49:45.384567: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55fc4e3c43b0 executing computations on platform Host. Devices:
2020-01-21 21:49:45.384598: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2020-01-21 21:49:45.448620: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.

因此,我能够使用
keras
&
tensor
流,但我得到的错误消息仍然与上面一样。

我以前没有使用过R,但是,当使用像Tensorflow这样的库时,我遇到了类似的环境问题。我在学习Tensorflow和Keras进行深度学习时也遇到了同样的问题。 在我的例子中,我发现这个洞的问题是由Tensorflow库本身造成的。我使用windows,但这可能也适用于linux,因此我所做的是:

  • 从您的计算机上卸载每个Conda、Python和R(包括tensorflow等附加库)
  • 我下载了las版本的“巨蟒”,但只下载了巨蟒,没有其他。事实上,这就是消除错误所需的全部内容
  • 继续安装,然后您将拥有Anaconda navigator。 默认情况下,包括应用程序和python(在anaconda navigator中),如Jupyter、Spyder和R
  • 转到环境部分,创建一个专用环境,在其中您将安装Tensorflow库。您可以在Anaconda navigator内的navigator中键入名称,以查找要插入的库
  • 确保在刚刚创建的新环境中安装了所需的孔库
  • 回到主页部分,确保您已选择“新建环境”安装您需要的应用程序,您可以在下面找到这些应用程序。其中R是可飞行的

  • 这应该行得通,我希望它能帮助你。这种方式比传统的pip安装过程更加清晰明了。请注意,Tensorflow不是一个简单的库,通过使用此方法,ANACONDA navigator可以很好地组织所有内容,以后不会出现错误。

    确保正确安装了conda或VirtualEnvironment。

    在尝试安装pip之前,您是否激活了conda或虚拟环境?我将如何激活它?安装Anaconda和Miniconda时,我可以选择
    是否希望安装程序通过运行conda init来初始化Miniconda3?
    我编写的
    。尝试使用
    $conda info--envs
    查看您的conda环境。如果您可以看到您命名的环境,请使用命令
    conda activate env_name
    I运行
    conda info--envs
    ,该命令提供了
    #conda环境:#/home/myuser/anaconda3 base*/home/myuser/miniconda3
    ,然后,
    conda activate/home/myuser/anaconda3
    。然后它“什么也没做”,只是添加了
    (/home/myuser/anaconda3)myuser@ip-132-21-61-131:~/folder_1
    而之前它只是
    (基本) myuser@ip-132-21-61-131:~/folder_1
    。我认为问题在于
    目录/usr/bin/python3.6中没有这样的文件或目录
    ,而
    install_keras()
    正试图在该目录中查找Python,但文件夹是创建的。
    perf = model %>% evaluate(x_test, y_test)
    print(perf)
    
    $loss
    [1] 0.2995828
    
    $acc
    [1] 0.84375