![](/img/trans.png)
[英]Installation of keras fails with Error: could not find a Python environment for /usr/bin/python3
[英]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
。 我在shell安裝了Miniconda並創建了conda環境:
conda activate r-reticulate
然后,在 R 中,我嘗試安裝 keras(與 package 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
,那么:
r-reticulate
: conda create -n r-reticulate
install_tensorflow(method = 'conda', envname = 'r-reticulate')
library(reticulate)
use_condaenv('r-reticulate')
library(tensorflow)
tf$constant("Hellow Tensorflow")
參考:
我使用virtualenv
安裝,我發現我必須通過envname
指定 env 的完整路徑。 它不適method="virtualenv", envname="r-reticulate"
希望有時間補充資料。 我嘗試按照 Anugerah Erlaut 所說的進行操作,但嘗試通過 WSL 在 R-studio Server 上安裝 Keras GPU。
我知道該解決方案會起作用,因為我在另一台計算機上嘗試過,但安裝在 Windows 和 Keras CPU 上。 經過一段時間的測試(並感到沮喪),似乎 Rstudio 沒有更改 r-reticulate env 的權限。
因此,我嘗試了在 bash 命令行上運行或“純 R”的解決方案,它工作得很好!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.