Keras/Tensorflow in RStudio not referencing Python in Miniconda Environment - python

so I've been trying to use Keras with Miniconda on my machine for a few weeks now (in Rstudio) and I've still been unable to make significant progress.
Most recently, here are the steps I followed:
create an environment in Miniconda, using Python 3.6
Download R and RStudio (an older version, Version 3.6.0) into said environment and run them
Install Keras into the environment (after Rcpp, Devtools etc)
Attempt to install Tensorflow
But then I get the error message that my Python installation isn't found and the bindings aren't loaded.
I've put the environment on the PATH, as well as the location where Python is and some folders within the environment.
I followed the advice given in a comment in my last post, which helped me to create the environment, but now Python isn't loading in Miniconda and I'm so so frustrated that I haven't been able to make this work. Please help.
When I look for the Python version I get this:
C:\Users\NK>python --version [1] Python 3.8.4rc1
Here is the beginning of the code I'm running:
library(keras)
library(tensorflow)
library(reticulate)
use_python("C:\\Users\\NK\\AppData\\Local\\Microsoft\\WindowsApps", required=T)
Sys.setenv(RETICULATE_MINICONDA_PATH = "C:/mini/envs/r_3.6.0.1")
mnist <- dataset_mnist()
and I get this error:
Error: Installation of Python not found, Python bindings not loaded. Use reticulate::install_miniconda() if you'd like to install a Miniconda Python environment. even though I'm doing this entirely in a Miniconda environment. I'm even opening RStudio straight from the Miniconda command prompt.
Some basic info: Dell XPS 15 running Windows 10, using RStudio
Side question: Is there an easier way to do all this? It's been fatiguing.

I finally got it to work! Here were my steps for anyone who stumbles across this:
Reinstall Anaconda
Create Anaconda Environment with Python 2.7 and R
Install Keras and Tensorflow packages and dependencies one by one into the environment through Anaconda
Install RStudio in the environment through Anaconda
use use_python("[env]", required=T) and Sys.setenv(RETICULATE_MINICONDA_PATH = "[env]") in any scripts you run using Keras

Related

How to update to spyder‑kernels=2.2?

Recently I started using Spyder for my python programming. One of the Code required QT version greater than 5.12 so I installed standalone version of Spyder. To install additional packages I am using Anaconda. Despite of creating virtual environment I am not able to use Spyder as kernel throws error. " The Python environment or installation whose interpreter is located at
/Users/ugowda/opt/anaconda3/bin/python
doesn't have the spyder‑kernels module or the right version of it installed (>= 2.2.1 and < 2.3.0). Without this module is not possible for Spyder to create a console for you.
You can install it by activating your environment (if necessary) and then running in a system terminal:
conda install spyder‑kernels=2.2
or
pip install spyder‑kernels==2.2.*"
Tried several online suggestions,didn't work. Did anyone face similar problem ? Do anyone has solution ?
I used this command after I activated my env:
pip install spyder-kernels==2.2.1

anaconda will not let me import files and therefore I cannot delete it or redownload it [duplicate]

I had a working deep learning library on CPU Linux Mint ubuntu verion 18.3 with Anaconda 3.6 but something got hosed when I was tinkering around in Theano.
https://machinelearningmastery.com/setup-python-environment-machine-learning-deep-learning-anaconda/
Everything was working just fine until I wanted to tinker around with a few .py files with KERAS_BACKEND=theano python program.py and in an attempt to fix something not working in Theano, I did this command from the theano website
http://deeplearning.net/software/theano_versions/dev/requirements.html
conda install numpy scipy mkl <nose> <sphinx> <pydot-ng>
Not knowing what I am doing it almost seemed to pooch everything... And install Python 2.7 dependencies. Would anyone be able to give me a tip on how reset my deep learning library in anaconda 3.6 build???
If I do a conda list anaconda$ its a custom build 2.7 which was not intentional! Time to start learning how to do virtual sessions :)
Read the docs for uninstalling Anaconda
https://docs.anaconda.com/anaconda/install/uninstall
Do a conda install anaconda-clean
Then a anaconda-clean --yes
Then re-download the Anaconda 5.2 For Linux Installer and run thru
the steps. https://www.anaconda.com/download/#linux
I had a similar problem and just did:
conda install --revision 0
this gives me a fresh Anaconda installation, with the drawback of needing to install every package again. Hovewer, all environments created remain intact.
More on Anaconda revisions here: https://medium.com/#wilpat456/fix-broken-anaconda-environment-due-to-recent-package-download-9094fb0f3a04

Why do I get an error trying to use keras package in R?

I'm trying to run through an example for building a neural network in R. I tried following the instructions at https://opendatascience.com/using-keras-and-tensorflow-in-r/.
I've installed the keras and tensorflow packages and I have the anaconda navigator downloaded on my laptop. When I run the following:
library(keras)
library(tensorflow)
reticulate::use_condaenv(“r-reticulate”)
mnist <- dataset_mnist()
I'm getting this error
Error in conda_python(envpath, conda = miniconda) :
no conda environment exists at path 'C:/Users/smurphy4/AppData/Local/r-miniconda/envs/r-reticulate'
This is probably a stupid question but I haven't used python before and I only have a little experience with R and would really appreciate any help.
Also, I don't know if this is relevant but when I open the anaconda navigator and look in environments, there isn't an r-reticulate environment, only a base (root) environment.Anaconda navigator environments
In case anyone has a similar problem, I just uninstalled Rstudio and installed again through a new python environment in anaconda navigator and installed the modules I needed in that environment. That seemed to work.

ModuleNotFoundError for Tensorflow and Anaconda (Windows 10)

I can't get tensorflow to work on two different Windows PCs and on both I get "ModuleNotFoundError: No module named 'tensorflow' when try to import them in python.
Numpy for example works on one machine not the other. Checked a dozen of posts on stackoverflow, nothing really helps. Clearly somethings wrong with the paths, can't really figure out what and how to trouble check it. I followed this set-up https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation-Windows.md
I need the 1.7.1 version of TF for Unity ML-agents to work
OS: windows 10
conda version : 4.4.11
conda-build version : 3.4.1
python version : 3.6.4.final.0
Even a clean install of Anaconda didn't help.
I finally managed to fix this (not with ML-agents, but that's a different story). I uninstalled Anaconda and Python as well as cleared the registry from all Python information. I had a previous installation of Python 3.7 and I'm guessing this might have caused some issues. Clean install of Anaconda with a 3.6 env and TF is working both with cpu and gpu support.
These problems often happen when you are on the wrong environment, or when you do not activate your environment. Please try the following steps and see if the problem persists:
Open Anaconda prompt
Activate the environment in which you installed tensorflow by using conda activate YOUR_ENV_NAME
Type python to launch python
try to import tensorflow
And see if the error persists.

How do you install Tensorflow on Windows?

I am trying to install Tensorflow on Windows.
I have Anaconda 4.2.0. I tried running
conda create -n tensorflow python=3.5
in my command prompt. This seemed to do something, but I'm not sure what this accomplished. It created a folder within the Anaconda3 program in my username folder.
This folder is filled with the following content:
Over the summer, I used mainly Jupyter Notebooks to do my python coding. Within this environment, there is a tab marked Condas
So it looks like I should be able to switch to the Tensorflow environment. But this doesn't work when I try to switch, there is no option to change my kernel to a Tensorflow one.
I tried running
conda search tensorflow
But nothing appears.
I'm not sure what to do. I asked a few grad students in my economics research group, but they weren't sure what to do either.
My Question
How do I properly install Tensorflow on Windows?
The syntax of the command is conda create -n <name_of_new_env> <packages>. As a result, you created a clean environment named tensorflow with only Python 3.5 installed. Since conda search tensorflow returned nothing, you will have to use pip or some other method of installing the package. Since there is spotty official support for Windows, the conda-forge package (CPU only) at https://github.com/conda-forge/tensorflow-feedstock is probably the best way.
People have also reported success installing Tensorflow with docker, if you have docker set up already.
I was able to run it under the Windows 10 linux subsystem (https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
Which is basically a linux environment within windows.
The latest tensorflow version (0.12) added windows support
https://www.tensorflow.org/get_started/os_setup#pip_installation_on_windows
just run:
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
(the url is for the specific version - you will need to change it for future versions or other setups)
An Anaconda environment isolates itself completely with the outer world, so all the packages you installed outside the virtualenv is nothing in the virtualenv, if you want to use Tensorflow in the environment(seems like the only way with Anaconda), use activate tensorflow command and install the packages you want seperately.
pip provides an easy method to install tensorflow on windows machine.
use the following pip command
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
Tensorflow only support python3.5 x64 bit on windows machines and it requires that you install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow

Categories

Resources