0

I'm running vscode using keras application on R with the following code (on R console):

library(foreign)
library(dplyr)
library(tidyverse)
library(tidytext)
library(keras)
library(data.table)
options(scipen=999) 

dat <- read.csv("https://www.dropbox.com/s/31wmgva0n151dyq/consumers.csv?dl=1")

max_words <- 2000 # Maximum number of words to consider as features
maxlen <- 64 # Text cutoff after n words

# Prepare to tokenize the text

texts <- as.character(dat$consumer_complaint_narrative)
tokenizer <- text_tokenizer(num_words = max_words) %>% 
  fit_text_tokenizer(texts)

But it says:

Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640Error in python_config(python_version, required_module, python_versions) : 
  Error 9009 occurred running C:\Users\my_working_directory\AppData\Local\MICROS~1\WINDOW~1\python.exe

It seems to suggest that I have not installed python on my device, but I actually did because I ran similar keras Python code on my jupyter notebook without problem, and I just want to try doing this in R. I have found others asked similar question before, but I could not figure on top of my mind what is the problem, at least for my case. It will be really appreciated if someone could help me on this.

Chris T.
  • 1,699
  • 7
  • 23
  • 45

1 Answers1

0

Have you checked that Python is in the default PATH?

From the docs:

3.6. Configuring Python To run Python conveniently from a command prompt, you might consider changing some default environment variables in Windows. While the installer provides an option to configure the PATH and PATHEXT variables for you, this is only reliable for a single, system-wide installation. If you regularly use multiple versions of Python, consider using the Python Launcher for Windows.

3.6.1. Excursus: Setting environment variables Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt.

To temporarily set environment variables, open Command Prompt and use the set command:

C:\>set PATH=C:\Program Files\Python 3.8;%PATH%  
C:\>set PYTHONPATH=%PYTHONPATH%; 
C:\My_python_lib  
C:\>python

These changes will apply to any further commands executed in that console, and will be inherited by any applications started from the console.

Including the variable name within percent signs will expand to the existing value, allowing you to add your new value at either the start or the end. Modifying PATH by adding the directory containing python.exe to the start is a common way to ensure the correct version of Python is launched.

To permanently modify the default environment variables, click Start and search for ‘edit environment variables’, or open System properties, Advanced system settings and click the Environment Variables button. In this dialog, you can add or modify User and System variables. To change System variables, you need non-restricted access to your machine (i.e. Administrator rights).

Note Windows will concatenate User variables after System variables, which may cause unexpected results when modifying PATH. The PYTHONPATH variable is used by all versions of Python 2 and Python 3, so you should not permanently configure this variable unless it only includes code that is compatible with all of your installed Python versions.

The path specified in the code snippet C:\Program Files\Python 3.8 must be adapted to reflect where your Python is actually located.

Séraphin
  • 710
  • 7
  • 18
  • Hi, thanks for you reply. Python is indeed in the default working directory, but it appears that `Rstudio` had difficulty executing the vscode. I read another thread suggesting that one launch `Rstudio` from Anaconda, which I did, but the problem being that it crashes on Win 10 every time when I launch it from Anaconda, but sure why... – Chris T. Feb 04 '20 at 19:09