Rpy2 error wac-a-mole: R_USER not defined - python

I'm running Python (x,y) 2.7 on windows 7 32 bit and R version 3.1.0. I've been trying to install Rpy2 and have been getting many errors. I finally found this site which has pre-compiled python modules for windows http://www.lfd.uci.edu/~gohlke/pythonlibs/, so I downloaded rpy2‑2.4.2.win32‑py2.7.exe. When I did this and tried
import rpy2.robjects as robjects
I had an error saying it could not find R_HOME, so I updated my path variables. This was fixed, but then I got an error saying it could not find R_USER. Once again, I updated my PYTHONPATH variables based on SO responses. This didn't work, and so I'm stuck. I've updated my PYTHONPATH both inside Spyder and also in my system variables, but still no luck. Does anyone know what could be going on? This is the error I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\rpy2\robjects\__init__.py", line 18, in <module>
from rpy2.robjects.robject import RObjectMixin, RObject
File "C:\Python27\lib\site-packages\rpy2\robjects\robject.py", line 5, in <module>
rpy2.rinterface.initr()
RuntimeError: R_USER not defined.
This is what my PYTHONPATH includes:
C:\Python27\Lib\site-packages\rpy2;C:\Program Files\R\R-3.1.0\bin\i386;C:\Python27\Lib\site-packages\rpy2\robjects
This is what my PATH includes:
C:\Python27\Lib\site-packages\PyQt4;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;c:\Program Files\Intel\DMIX;C:\Program Files\Intel\Services\IPT\;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\Lib\site-packages\vtk;C:\Python27\gnuplot\binary;C:\Program Files\pythonxy\SciTE-3.1.0;C:\Program Files\pythonxy\console;C:\MinGW32-xy\bin;C:\Program Files\R\R-3.1.0\bin;C:\MinGW32-xy\mingw32\bin;C:\MinGW32-xy\bin
Thanks for any help you can provide!

You need to set the R_USER environment variable, e.g. to the username of the Windows account you use. See also this quote from this link:
1) Add the path to R.dll to my PATH variable (I went to the 32-bit directory) 2) Add an environment variable R_HOME (C:\Program Files\R\R-2.12.1 for me) 3) Add an environment variable R_USER (simply my username in Windows).

Related

ModuleNotFoundError: No module named 'asyncio.streams'

i am working on a long project in Django and suddenly i faced this error:
import asyncio
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio\__init__.py", line 17, in <module>
from .streams import *
ModuleNotFoundError: No module named 'asyncio.streams'
I tried to instal it using : pip install asyncio, But again it gave some errors :
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python38\lib\shutil.py", line 587, in _rmtree_unsafe
with os.scandir(path) as scandir_it:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\AppData\\Local\\Temp\\pip-req-tracker-ua43f6rj'
please Tell me how can i fix it . I am Using Python 3.8.1
Please reinstall python3.8.1 for windows 10
Packages and modules in python can be imported when they appear in the PYTHONPATH environement variable or in the sys.path list.
On each PYTHONPATH expanding, will ends up in the sys.path list.
so make sure that, the instalation of your asyncio was successeful and its path exist in the sys.path list. how you check? see below:
in comand line or in script.py type:
import sys
p_asyn=r'C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio'
if p_asyn not in sys.path:
print('asyncio not in the sys path list! :-(')
sys.path.append(p_asyn)
its better to append new paths to the PYTHONPATH rather than editing the sys.path.
Anywa, if the module you are trying to import (asuncio) is a built in lib/module you should check if the pyhton installation was successful and the path environement variable edited correctly and has all paths that should be.
in windows make sure that python installation dir appears in the path. if not use the set command,
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Python usually stores its library (and thereby your site-packages folder) in the installation directory. So, if you had installed Python to C:\Python\, the default library would reside in C:\Python\Lib\ and third-party modules should be stored in C:\Python\Lib\site-packages.
This attended to windows users.
for further reading, enter the link here
using_py2
using_py3

Unable to import git in python

I am facing these issues. Can you help me with the same ?
Why am I seeing this error ? Do I have to add anything in the requirements.txt file ?
>>> import git
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
import git
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
>>> from git import Repo
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from git import Repo
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
I already had gitdb and smmap installed so I had to reinstall them.
You can reinstall them by running the following command in your terminal:
pip3 install --upgrade --force-reinstall gitdb; pip3 install --upgrade --force-reinstall smmap
I also got the message ImportError: 'gitdb' could not be found in your PYTHONPATH (when trying to use GitPython).BUT I had gitdb already installed!
Thanks to this hint I figured out that gitdb silently failed because it was missing smmap.
So I installed this and it worked.
You need to install gitdb package.
$ sudo easy_install gitdb
I had the same problem. However, gitdb and smmap were already installed by pip. As I used brew to install python and its dependencies on my mac, when I checked brew doctor command, it said that my /usr/local/sbin directory is not in my PATH. So I added it to my PATH (though it didn't have anything to do with the python) and everything worked out eventually.
MS Windows Versions of this problem can occur because of the order of Python versions in your system PATH, as it did for me. I did not realize that when I installed another program, it installed a newer version of Python for its own usage, and it appended my system PATH with the address to the newer version. I noticed it when I looked at the PATH variable and found two versions of Python being called. Windows uses the first it finds, and if the first doesn't match what your program expects, it gets confused and can't find the right path to the module. This is what I did to resolve it:
To check: an easy way to test if this is your problem is to see if the paths separated by semicolons are in the right order. That can be seen in the System Variables of Windows or by printing your PATH variable in your CMD shell like in this example:
C:> path
PATH=C:\Program Files (x86)\Python37-32\Scripts;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\WINDOWS
Temporary solution:
To see if it is going to fix your computer, change it in your CMD window. Your variable change will be discarded when the window is closed. One way to do this test is to copy the paths, move the Python references to the order they are needed, and write it back:
C:> set path = C:\WINDOWS;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\Program Files (x86)\Python37-32\Scripts\
Then run the Python program to see if this was your problem. Note that this is only an example; do not copy & paste it. Your path is customized for the programs on your computer.
Permanent solution: If the above test resolves your problem, you must change your System Variables to make the change permanent. For me that usually requires a reboot afterwards in order to make the variables appear in all new windows.

JPype won't compile properly

So I am having trouble compiling a very simple python script using JPype.
My code goes like:
from jpype import *
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
and when I run it I receive an error saying:
Traceback (most recent call last): File "test.py", line 2, in
<module>
startJVM(getDefaultJVMPath(), "-ea") File "/usr/lib/pymodules/python2.7/jpype/_core.py", line 44, in startJVM
_jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error =
/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared
object file: No such file or directory at
src/native/common/include/jp_platform_linux.h:45
I'm stuck and I really need help. Thanks!
I had the same problem
RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error = /usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared object file: No such file or directory at src/native/common/include/jp_platform_linux.h:45
In my case wrong JAVA_HOME path was set
/profile/etc
export JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH="$JAVA_HOME/bin:$PATH"
export PATH
The work around is to define the full path directly in the call to the JVM:
from jpype import *
startJVM('/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/MacOS/libjli.dylib', "-ea", "-Djava.class.path=/tmp/Jpype/sample")
java.lang.System.out.println("Hello World!!")
shutdownJVM()
Original text:
Similar issues when trying to run JPype on MacOS El Capitan. I could
not figure out how to coax the _darwin.py code finding the correct JVM
location, despite the JAVA_HOME system variable being set properly.
Caveat cursor, trying to run the above code in the Spyder IPython console did not produce any output, but the normal Console would.

Setting Environmental Variables for Python on a Mac - seems not to work?

This Drives me nuts...
I use the latest EPD Distribution on the latest Mac and I want to study the book "Python for software design". Therein, Chap. 4, is one should load to play around with.
But to do that I seemingly need to set a PATH variable to the relevant directory. As I am not very familiar I looked around and finally added this to my .bash-profile:
"PYTHONPATH="$HOME/Dropbox/Programming/swampy-2.0"
The check with the Terminal:
Andreass-Mac-mini:~ ak$ $PYTHONPATH
-bash: /Users/ak/Dropbox/Programming/swampy-2.0: is a directory
Up to this point I would say it should work. And then comes this:
>>> from TurtleWorld import *
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from TurtleWorld import *
ImportError: No module named TurtleWorld
It is the right file name, the correct directory and it seems to me that the path is not right?
So what do I have to do/change that it works on my Mac?
Edit: and by the way - (on a different) I also created a directory .MacOSX and put the file environment.plist therein with the same path variable. Nothing changed :-(
Thanks
Andreas
Use the export command in your .bash-profile to make environment variables appear in other contexts:
export PYTHONPATH=$HOME/Dropbox/Programming/swampy-2.0
Did you name your script Turtleworld.py? If so, that is the issue. The module can't be imported if your script name is the same as the module name. Hope this helps! :D

libgeos_c-1.dll can't be loaded by Python

I'm building my first GeoDjango project but I'm kinda desperate.
I'v installed PostgreSQL 9 and PostGis 1.5 through one-click installer on Windows. So everthing is there. I set GEOS_LIBRARY_PATH to the full path of libgeos_c-1.dll in settings.py. But when I run manage.py syncdb, I encounter the following errors:
File "C:\Python25\lib\site-packages\django\contrib\gis\geometry\backend\geos.py", line 1, in <module>
from django.contrib.gis.geos import \
File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\__init__.py", line 6, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\geometry.py", line 14, in <module>
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\coordseq.py", line 9, in <module>
from django.contrib.gis.geos.libgeos import CS_PTR
File "C:\Python25\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 51, in <module>
lgeos = CDLL(lib_path)
File "C:\Python25\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
So I open libgeos.py and check the line specified. It's just a simple "CDLL(lib_path)". Apparently lib_path is GEOS_LIBRARY_PATH.
So I create a simple test:
from ctypes import CDLL
lgeos = CDLL('libgeo's path')
Still have the same problem. So it's simply not able to use CDLL to load this dll at all with python. At this stage, I don't know what to do. Please help.
Aparently after set GEOS_LIBRARY_PATH variable using doble '\' slashes works for me, but now launches this error 'module' object has no attribute 'OSMGeoAdmin'
I just run into the same problem after installing Postgresql 9.1 and postgis 2.0 via Windows installers. No need to download anything else. All you have to do is adding this directory into the Windows path: C:\PostgreSQL\9.1\bin or wherever the libgeos_c-1.dll file lives. You may need to reboot if you want the new environment variables to take effect for your IDE. For command lines, just open a new command prompt.
Doing this this way makes setting GEOS_LIBRARY_PATH optional since the required files are already in Windows path.
This may not have worked for the OP back in 2010 but for others who run into the same problem in 2012 going forward, it's probably the simplest solution.
Different things come to my mind, the most obvious being: You did paste the path to the DLL file in there, not just the folder it resides in? No offense meant, just to be on the safe side.
Then, you might also get this error if there are unresolved dependencies, i.e. the DLL's LoadLibrary fails because it is missing another library it depends on. You can easily find that out using Dependency Walker. Load libgeos with depends and look for missing modules, error messages etc. - you might be missing libgeos-X-Y-Z.dll, for example.
Same issue here. Could you maybe be so kind as to share the correct DLL? If that indeed solves the problem. Or is installing OSGeo4W the only way?If so what installation procedure did you follow?
I had the same issue and solved it by:
Reinstalling http://trac.osgeo.org/osgeo4w/ (my installation folder is C:\OSGeo4W64\)
adding the line:
GEOS_LIBRARY_PATH = 'C:\OSGeo4W64\bin\geos_c.dll'
to settings.py
(following this answer: https://stackoverflow.com/a/21495785/2314737)
This is also mentioned in the official documentation:
When GeoDjango can’t find GEOS, this error is raised:
ImportError: Could not find the GEOS library (tried "geos_c"). Try
setting GEOS_LIBRARY_PATH in your settings. The most common solution
is to properly configure your Library environment settings or set
GEOS_LIBRARY_PATH in your settings.

Categories

Resources