title: How to set environment variable R_User? And how to get module winreg?
body: <p>I'm trying to run a Python program that uses rpy2. Installation was successful, I think. But when I try to run it, I get the following error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):</p>
    
    <p>File "", line 1, in 
        runfile('C:/Users/(file location)', wdir='C:/Users/(file location)')</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 827, in runfile
        execfile(filename, namespace)</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)</p>
    
    <p>File "C:/Users/(file location)", line 5, in 
        from rpy2.robjects import r</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\rpy2\robjects__init__.py", line 19,
    in 
        from rpy2.robjects.robject import RObjectMixin, RObject</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\rpy2\robjects\robject.py", line 6,
    in 
        rpy2.rinterface.initr()</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\rpy2\rinterface__init__.py", line
    208, in initr
        _initr(r_preservehash=r_preservehash)</p>
    
    <p>RuntimeError: R_USER not defined.</p>
  </blockquote>
  
  <p>I found a question that addresses just this problem: <a href="https://stackoverflow.com/questions/24414540/rpy2-error-wac-a-mole-r-user-not-defined">Rpy2 error wac-a-mole: R_USER not defined</a>. The answer says to set the R_user environment variable. Unfortunately, I don't know how to do that; I hadn't even heard of an environment variable before until this. I followed the only lead I saw: the link in the answer. That led to a webpage with two downloadable python files: set_Rvars32_win32.py and setup.py. I tried running both, but they both yield an error. Here is the traceback for set_Ravars32_win32.py </p>
  
  <blockquote>
    <p>Traceback (most recent call last):</p>
    
    <p>File "", line 1, in 
        runfile('C:/Users/(my name)/Anaconda3/set_Rvars_win32.py', wdir='C:/Users/Jin/Anaconda3')</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 827, in runfile
        execfile(filename, namespace)</p>
    
    <p>File "C:\Users(my
    name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)</p>
    
    <p>File "C:/Users/(my name)/Anaconda3/set_Rvars_win32.py", line 4, in
    
        import _winreg</p>
    
    <p>ModuleNotFoundError: No module named '_winreg'</p>
  </blockquote>
  
  <p>setup.py yields the same error and the same traceback sequence (except of course the file is C:/Users/(my name)/Anaconda3/setup.py)</p>
  
  <p>I then tried running the Anaconda Prompt (Anaconda3).</p>
  
  <p>pip install _winreg yields </p>
  
  <p>ERROR: Invalid requirement: '_winreg'</p>
  
  <p>pip install winreg yields </p>
  
  <p>Collecting winreg</p>
  
  <p>ERROR: Could not find a version that satisfies the requirement winreg (from versions: none)</p>
  
  <p>ERROR: No matching distribution found for winreg</p>
  
  <p>Am I on the right track? Or is there an easier way to set environment variables?</p>
  
  <p>Thanks</p>