Impossible to use keras in R - tensorflow

I have been trying to install Keras in R. Previously I have done that in another machine , it worked well there, but now i am facing problems.
Codes:
library(devtools)
devtools::install_github("rstudio/reticulate")
devtools::install_github("rstudio/keras")
devtools::install_github("rstudio/tensorflow")
install_keras()
All worked well, but when i am trying to load any inbuilt dataset or run in keras functions its giving me error like this.(along with a dialog box : rssesion.exe Entry point not found)
image=image_load(" D:/CT images/image1.png")
Error in image_load(" D:/CT images/image1.png") :
The Pillow Python package is required to load images
> mnist <- dataset_mnist()
Error: C:/Users/user/ANACON~1/envs/R-TENS~1/python36.dll - The specified
procedure could not be found.
I have checked the output of :
reticulate::py_discover_config("keras")
reticulate::py_discover_config("tensorflow")
Output :
> reticulate::py_discover_config("keras")
python: C:\Users\user\ANACON~1\envs\R-TENS~1\python.exe
libpython: C:/Users/user/ANACON~1/envs/R-TENS~1/python36.dll
pythonhome: C:\Users\user\ANACON~1\envs\R-TENS~1
version: 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC
v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\user\ANACON~1\envs\R-TENS~1\lib\site-packages\numpy
numpy_version: 1.14.3
keras: [NOT FOUND]
python versions found:
C:\Users\user\ANACON~1\envs\R-TENS~1\python.exe
C:\Users\user\ANACON~1\python.exe
C:\Users\user\Anaconda3\python.exe
C:\Users\user\Anaconda3\envs\r-tensorflow\python.exe
> reticulate::py_discover_config("tensorflow")
python: C:\Users\user\Anaconda3\envs\r-tensorflow\python.exe
libpython: C:/Users/user/Anaconda3/envs/r-tensorflow/python36.dll
pythonhome: C:\Users\user\ANACON~1\envs\R-TENS~1
version: 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC
v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\user\ANACON~1\envs\R-TENS~1\lib\site-packages\numpy
numpy_version: 1.14.3
tensorflow: C:\Users\user\ANACON~1\envs\R-TENS~1\lib\site-
packages\tensorflow\__init__.p
python versions found:
C:\Users\user\Anaconda3\envs\r-tensorflow\python.exe
C:\Users\user\ANACON~1\envs\R-TENS~1\python.exe
C:\Users\user\ANACON~1\python.exe
C:\Users\user\Anaconda3\python.exe
I have installed the latest version of Anaconda and also installed latest version of R and Rstudio.
I cant understand the problem since I am a beginner. Please help

I was able to install and use Keras in R using the following commands. I haven't faced any issues.
devtools::install_github("rstudio/keras")
library(keras)
install_keras()

Related

`conda search PKG --info` shows different dependencies than what conda wants to install?

I'm building a new conda environment using python=3.9 for the
osx-arm64 architecture.
conda create -n py39 python=3.9 numpy
conda list
...
numpy 1.21.1 py39h1a24bff_2
...
python 3.9.7 hc70090a_1
So far so good: numpy=1.21.1 is the one i want. Now I want to add
scipy, and the first one seems to fit the bill:
conda search scipy --info
scipy 1.7.1 py39h2f0f56f_2
--------------------------
file name : scipy-1.7.1-py39h2f0f56f_2.conda
name : scipy
version : 1.7.1
build : py39h2f0f56f_2
build number: 2
size : 14.8 MB
license : BSD 3-Clause
subdir : osx-arm64
url : https://repo.anaconda.com/pkgs/main/osx-arm64/scipy-1.7.1-py39h2f0f56f_2.conda
md5 : edbd5a5399e973d1d0325147b7118f79
timestamp : 2021-08-25 16:12:39 UTC
dependencies:
- blas * openblas
- libcxx >=12.0.0
- libgfortran 5.*
- libgfortran5 >=11.1.0
- libopenblas >=0.3.17,<1.0a0
- numpy >=1.19.5,<2.0a0
- python >=3.9,<3.10.0a0
in particular, python >=3.9 and numpy >=1.19 seems just right.
but when i try the install
conda install scipy
...
The following packages will be DOWNGRADED:
numpy 1.21.1-py39h1a24bff_2 --> 1.19.5-py39habd9f23_3
(I have bumped into various constraints with numpy=1.19 (numba,
pandas,) and am trying to avoid it.)
Why isn't the scipy package happy with the numpy=1.21 version I
have?!
The only possible clue is that conda reports a different python
version (3.8.11) than the v3.9 I specified for this environment:
conda info
active environment : py39
active env location : .../miniconda3/envs/py39
shell level : 1
user config file : .../.condarc
populated config files : .../.condarc
conda version : 4.11.0
conda-build version : not installed
python version : 3.8.11.final.0 <-------------------
virtual packages : __osx=12.1=0
...
but all the environment's pointers seem to be set correctly:
(py39) % which python
.../miniconda3/envs/py39/bin/python
(py39) % python
Python 3.9.7 (default, Sep 16 2021, 23:53:23)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Thanks, any hints as to what's broken will be greatly appreciated!
I now have things working, but I'm afraid I can't point to a satisfying "answer." Others (eg #merv) seem to not be having the same problems and I can't identify the difference.
The one thing that I did find that seemed to create issues in my install was what seems to be some mislabeling of the pandas package: pandas v1.3.5 breaks a numpy==1.19.5 requirement that is the only way i've been able to push it thru. i posted a pandas issue comment

'Could not find a version that satisfies the requirement matplotlib==3.4.3' problem on Python 3.10

I need help with pip install -r matplotlib==3.4.3 on Python 3.10.
Here's my CMD output:
Collecting matplotlib==3.4.3
Downloading matplotlib-3.4.3.tar.gz (37.9 MB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: `'C:\Users\eob_o\venv\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'`
C:\\Users\\eob_o\\AppData\\Local\\Temp\\pip-install-txwy9aql\\matplotlib_201a53d35123474cbeaa8a08acd5c0c5\\setup.py'"'"'
ERROR: Command errored out with exit status 1:
command: `'C:\Users\eob_o\venv\Scripts\python.exe' 'C:\Users\eob_o\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py'` build_wheel
'C:\Users\eob_o\AppData\Local\Temp\tmpqjub6dxu'
Complete output (200 lines):
setup.py:63: RuntimeWarning: NumPy 1.21.2 may not yet support Python 3.10.
warnings.warn(#Running from numpy source directory.
C:\Users\eob_o\AppData\Local\Temp\pip-wheel_qobiqz_\numpy_24f149b83cd943538729a21c1b35fa75\tools\cythonize.py:69:
DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.version import LooseVersion
Processing numpy/random\_bounded_integers.pxd.in
Processing numpy/random\bit_generator.pyx
Processing numpy/random\mtrand.pyx
Processing numpy/random\_bounded_integers.pyx.in
Processing numpy/random\_common.pyx
Processing numpy/random\_generator.pyx
Processing numpy/random\_mt19937.pyx
Processing numpy/random\_pcg64.pyx
Processing numpy/random\_philox.pyx
Processing numpy/random\_sfc64.pyx
...
BUILDING MATPLOTLIB
matplotlib: yes [3.4.3]
python: yes [3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC
v.1929 64 bit (AMD64)]]
platform: yes [win32]
tests: no [skipping due to configuration]
macosx: no [Mac OS-X only]
----------------------------------------
WARNING: Discarding
https://files.pythonhosted.org/packages/21/37/197e68df384ff694f78d687a49ad39f96c67b8d75718bc61503e1676b617/matplotlib-3.4.3.tar.gz#sha256=fc4f526dfdb31c9bd6b8ca06bf9fab663ca12f3ec9cdf4496fb44bc680140318 (from https://pypi.org/simple/matplotlib/) (requires-python:>=3.7).
Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement matplotlib==3.4.3 (from versions: 0.86, 0.86.1, 0.86.2, 0.91.0, 0.91.1, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.1rc1, 1.4.1, 1.4.2, 1.4.3, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 2.0.0b1, 2.0.0b2, 2.0.0b3, 2.0.0b4, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.1.0rc1, 2.1.0, 2.1.1, 2.1.2, 2.2.0rc1, 2.2.0, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 3.0.0rc2, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0rc1, 3.1.0rc2, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0rc1, 3.2.0rc3, 3.2.0, 3.2.1, 3.2.2, 3.3.0rc1, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.4.0rc1, 3.4.0rc2, 3.4.0rc3, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.5.0b1, 3.5.0rc1)
ERROR: No matching distribution found for matplotlib==3.4.3
By following the clue setup.py:63: RuntimeWarning: NumPy 1.21.2 may not yet support Python 3.10., I decided to uninstall Python 3.10 and replace with Python 3.9. And my problem got solved!

cannot get deepwater to run on MBP with TF

I am trying to run to get R + deepwater + tensorflow to work on a MBP.
The following have been installed.
Python 3.6.1
TensorFlow 1.1
The Hello, TensorFlow example on the TensorFlow website is working fine.
R version 3.4.0
curl -O http://h2o-release.s3.amazonaws.com/h2o/master/3904/R/src/contrib/h2o_3.11.0.3904.tar.gz
R CMD INSTALL h2o_3.11.0.3904.tar.gz
curl -O http://s3.amazonaws.com/h2o-deepwater/public/nightly/latest/h2o_3.11.0.tar.gz
R CMD INSTALL h2o_3.11.0.tar.gz
I am trying run the following example provided on the h2o website.
require(h2o)
h2o.init()
train <- h2o.importFile("https://h2o-public-test-data.s3.amazonaws.com/bigdata/laptop/mnist/train.csv.gz")
target <- "C785"
features <- setdiff(names(train), target)
train[target] <- as.factor(train[target])
model <- h2o.deepwater(x=features, y=target, training_frame=train, epochs=100, activation="Rectifier",
hidden=c(200,200), ignore_const_cols=FALSE, mini_batch_size=256, input_dropout_ratio=0.1,
hidden_dropout_ratios=c(0.5,0.5), stopping_rounds=3, stopping_tolerance=0.05,
stopping_metric="misclassification", score_interval=2, score_duty_cycle=0.5, score_training_samples=1000,
score_validation_samples=1000, nfolds=5, gpu=FALSE, seed=1234, backend="tensorflow")
The error I get is Error: java.lang.RuntimeException: Unable to initialize backend: Cannot find TensorFlow native library for OS: darwin, architecture: x86_64. Based on what I read on SO and the git page, I was under the impression that one does not need to build for the Mac platform.
One other thing that I tried was to use the info from https://github.com/rstudio/tensorflow. When I run install_tensorflow() I get Error: Prerequisites for installing TensorFlow not available. Please help!
We don't provide H2O+deepwater builds for MacOS. The one you downloaded is built for Linux machines (tested on Ubuntu), it's mentioned on the download page.
If you want to run it on MacOS you'd have to build both DeepWater and then H2O yourself.

Mac Lion Python install: Matplotlib ends in mysql error

I am setting up python/numpy/scipy/matplotlib/mysql on my Mac Lion. I first installed Python 2.7.3 and mysqldb. I then updated to XCode 4.3.3 and used the ScipySuperpack to install numpy, scipy, etc.
at this point I am able to import several packages in python without incident but matplotlib dies as follows:
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import _mysql
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg/_mysql.py:3:
UserWarning: Module _mysql was already imported from
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg/_mysql.pyc, but
/Users/myname/pypy is being added to sys.path
>>> import matplotlib
Error 2002: Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)
Sorry if the question is basic but I don't understand the warning, or what it may have to
do with the eventual error...
Strange. There is probably some internal namespace collision going on (given that this doesn't happen if you are in the mysql build directory). Matplotlib does not use mysql in any way, I checked this from a clone of the matplotlib source with:
$> grep -ir mysql *
And got no hits. But I guess the obvious answer is not to import matplotlib from within the mysql build directory...

Eye of Gnome Python plugins won't autogen because check for PYGTK fails

Presenting symptom: autogen disables the build of slideshowshuffle and pythonconsole, reporting "no python support." Platform is Ubuntu 9.04, Jaunty Jackalope; Gnome 2.26.1.
Log extract:
checking for a Python interpreter with version >= 2.3... python
checking for python... /usr/bin/python
checking for python version... 2.6
checking for python platform... linux2
checking for python script directory... ${prefix}/lib/python2.6/site-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.6/site-packages
checking for PYGTK... no
configure: WARNING: Python not found, disabling python support
Evidence that both python and pygtk are installed:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>>
I note the capitalization of PYGTK, which is common for environment variables. There is no PYGTK environment variable.
Your search - "PYGTK environment
variable" - did not match any
documents.
A grep for PYGTK in the tree rooted from /usr/share/doc/python-gtk2-doc/html returned no rows.
Try installing "python-gtk2-dev" package. You can make sure you have it with
pkg-config --list-all | grep pygtk-2.0
I think, the one you're using from python is "python-gtk2".