In order to install Tensor Flow for R, we will have to install Python first. In addition, we might install Jupyter Notebook and Jupyter Lab as well in case we want to run Python code. Another option for installing Python with Jupyter is to install Anaconda, which includes Python and options to install Jupyter and other packages later.
Install Python
- Go to https://www.python.org/downloads/release/python-390/ and download Python 3.9 for Windows 64-bit (later versions may not work for Tensor Flow package).
- Double click to install Python (choose Custom Installation for all users. Check
Add python.exe to PATH box.
- Select all optional features in the next screen if you choose customized installation
- Select Install Python 3.9 for all users for customized installation and add Python to environment variables
- Press Install to finish installing Python
Install Jupyter Lab
- Run CMD as Administrator
- To check your Python installation, type command: python --version
- Type following commands to install Jupyter Notebook and Jupyter Lab:
pip install notebook
pip install ipykernel
python -m ipykernel install
pip install jupyterlab
- You may also try to install packages using pip, for example, openpyxl package for managing Excel data and Pillow for pictures:
pip install openpyxl
pip install Pillow
- To open JupyterLab, type command: jupyter lab
- Try to run the following Python code to copy a picture named A11.jpg into the A1 cell of your Excel file:
import openpyxl
from openpyxl.drawing.image import Image
workbook = openpyxl.Workbook()
worksheet = workbook.active
img = Image('c:\\temp\\A11.jpg')
worksheet.add_image(img, 'A1')
workbook.save('c:\\temp\\photo.xlsx')
Install Tensor Flow
- Open R
- Install Tensor Flow Package by command:
install.packages("keras")
library(keras)
#assume your installed python into C:\Program Files\Python39\
reticulate::use_python("C:\\Program Files\\Python39\\python.exe")
reticulate::py_install("tensorflow")
reticulate::py_install("keras")
3. Restart R
4. Type commands:
library(keras)
install_keras()
5. Try the installation with commands:
model = keras_model_sequential()
Errors and Fixes:
- If you get error messages saying "multiple virtualenv exist or default vitualenv not compatible" or something like that, go to your R working directory (you can find it out by the command getwd() in R), go the directory, delete .virtualenv folder. And then perform the installation as normal.
|