Python in R - Error: could not find a Python environment for /usr/bin/python
Python in R - Error: could not find a Python environment for /usr/bin/python
我不明白 R 如何处理 Python 环境和 Python 版本并不断收到错误 Error: could not find a Python environment for /usr/bin/python
。我安装了 Miniconda 并在 shell:
中创建了一个 conda 环境
conda activate r-reticulate
然后,在 R 中,我尝试安装 keras(与包 tensorflow 相同的问题):
library(keras)
reticulate::use_condaenv()
install_keras(method = "conda", conda = reticulate::conda_binary())
... 并得到以下错误:
Error: could not find a Python environment for /usr/bin/python
我试图弄清楚 Python R 应该使用什么
reticulate::py_config()
并得到
python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Jul 5 2020, 02:24:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.21) (-macos10.15-objc-
numpy: /Users/bestocke/Library/Python/2.7/lib/python/site-packages/numpy
numpy_version: 1.16.6
tensorflow: [NOT FOUND]
python versions found:
/usr/bin/python3
/usr/local/bin/python3
/usr/bin/python
我不明白这个。这似乎是在使用 Python 2.7。当试图找出 shell 中使用了哪个 Python 时,我得到:
> which python
/opt/miniconda3/envs/r-reticulate/bin/python
和
> ls -l /opt/miniconda3/envs/r-reticulate/bin/python
lrwxr-xr-x 1 username wheel 9 Aug 2 15:21 /opt/miniconda3/envs/r-reticulate/bin/python -> python3.6
建议使用 Python 3.6。
我哪里错了?
尝试按照 https://tensorflow.rstudio.com/installation/ 上的指南进行操作:
在您的 R-studio 控制台中:
install.packages("tensorflow")
library(tensorflow)
install_tensorflow()
如果您还没有手动安装 Anaconda / Miniconda,那么在第 1 步。 3、一个提示会询问你是否允许安装Miniconda。如果您已经安装了 conda
,那么:
- 在 conda 中创建新环境
r-reticulate
:conda create -n r-reticulate
- 从 R-studio 控制台使用参数安装 tensorflow:
install_tensorflow(method = 'conda', envname = 'r-reticulate')
- 加载网状包
library(reticulate)
- 在R-studio
use_condaenv('r-reticulate')
激活conda环境
- 加载tensorflow库
library(tensorflow)
- 检查tensorflow是否激活
tf$constant("Hellow Tensorflow")
参考资料:
希望有时间补充信息。我尝试按照 Anugerah Erlaut 所说的进行操作,但尝试通过 WSL 在 R-studio 服务器上安装 Keras GPU。
我知道该解决方案可行,因为我在另一台计算机上尝试过,但安装在 Windows 和 Keras CPU 上。经过一段时间的测试(并感到沮丧),Rstudio 似乎没有权限更改 r-reticulate env.
所以,我在 bash 命令行上尝试了解决方案 运行 或“纯 R”,它工作得很好!
我使用 virtualenv
安装,我发现我必须通过 envname
指定环境的完整路径。它不适用于 method="virtualenv", envname="r-reticulate"
我不明白 R 如何处理 Python 环境和 Python 版本并不断收到错误 Error: could not find a Python environment for /usr/bin/python
。我安装了 Miniconda 并在 shell:
conda activate r-reticulate
然后,在 R 中,我尝试安装 keras(与包 tensorflow 相同的问题):
library(keras)
reticulate::use_condaenv()
install_keras(method = "conda", conda = reticulate::conda_binary())
... 并得到以下错误:
Error: could not find a Python environment for /usr/bin/python
我试图弄清楚 Python R 应该使用什么
reticulate::py_config()
并得到
python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Jul 5 2020, 02:24:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.21) (-macos10.15-objc-
numpy: /Users/bestocke/Library/Python/2.7/lib/python/site-packages/numpy
numpy_version: 1.16.6
tensorflow: [NOT FOUND]
python versions found:
/usr/bin/python3
/usr/local/bin/python3
/usr/bin/python
我不明白这个。这似乎是在使用 Python 2.7。当试图找出 shell 中使用了哪个 Python 时,我得到:
> which python
/opt/miniconda3/envs/r-reticulate/bin/python
和
> ls -l /opt/miniconda3/envs/r-reticulate/bin/python
lrwxr-xr-x 1 username wheel 9 Aug 2 15:21 /opt/miniconda3/envs/r-reticulate/bin/python -> python3.6
建议使用 Python 3.6。
我哪里错了?
尝试按照 https://tensorflow.rstudio.com/installation/ 上的指南进行操作:
在您的 R-studio 控制台中:
install.packages("tensorflow")
library(tensorflow)
install_tensorflow()
如果您还没有手动安装 Anaconda / Miniconda,那么在第 1 步。 3、一个提示会询问你是否允许安装Miniconda。如果您已经安装了 conda
,那么:
- 在 conda 中创建新环境
r-reticulate
:conda create -n r-reticulate
- 从 R-studio 控制台使用参数安装 tensorflow:
install_tensorflow(method = 'conda', envname = 'r-reticulate')
- 加载网状包
library(reticulate)
- 在R-studio
use_condaenv('r-reticulate')
激活conda环境
- 加载tensorflow库
library(tensorflow)
- 检查tensorflow是否激活
tf$constant("Hellow Tensorflow")
参考资料:
希望有时间补充信息。我尝试按照 Anugerah Erlaut 所说的进行操作,但尝试通过 WSL 在 R-studio 服务器上安装 Keras GPU。
我知道该解决方案可行,因为我在另一台计算机上尝试过,但安装在 Windows 和 Keras CPU 上。经过一段时间的测试(并感到沮丧),Rstudio 似乎没有权限更改 r-reticulate env.
所以,我在 bash 命令行上尝试了解决方案 运行 或“纯 R”,它工作得很好!
我使用 virtualenv
安装,我发现我必须通过 envname
指定环境的完整路径。它不适用于 method="virtualenv", envname="r-reticulate"