R_HOME Error with rpy2 - python

I know there are quite a few posts on getting up and running with rpy2 on windows 7 32 bit. I have referenced a good number of them and attempted their solutions, including the use of PypeR.
I dont explicitly have a R_HOME variable set in my path, but per this question, I confirmed that R is in my PATH (I can type R at the command line and get R to run) and even copied all of the files from the i386 folder to the parent bin folder.
My issue is pasted below. Any thoughts?
In [5]: from rpy2 import robjects
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-5-1f019d00d232> in <module>()
----> 1 from rpy2 import robjects
C:\Anaconda\lib\site-packages\rpy2\robjects\__init__.py in <module>()
16 import rpy2.rlike.container as rlc
17
---> 18 from rpy2.robjects.robject import RObjectMixin, RObject
19 from rpy2.robjects.vectors import *
20 from rpy2.robjects.functions import Function, SignatureTranslatedFunction
C:\Anaconda\lib\site-packages\rpy2\robjects\robject.py in <module>()
3 import rpy2.rinterface
4
----> 5 rpy2.rinterface.initr()
6
7 import conversion
RuntimeError: R_HOME not defined.

I confirm this issue is related to R_HOME variable not defined.
In my opinion, all of these issues are caused because the developers of rpy2 package haven't documented properly the requirements of their software:
Install R
Create R_HOME system variable
Add R_HOME\bin to the PATH, in order to execute R from python
Add R_HOME\bin\x64 to the PATH, in order to load R.dll
Install package tzlocal

With help from the comment above, I got moving in the proper direction. I created the R_HOME as a SYSTEM variable. That didn't work right away, as I was getting an R_USER not defined error.
To get everything the import above to work without error, I simply re-installed the rpy2 exectuable from here after defining the R_HOME. No errors.
In summary, key was o have R_HOME set PRIOR TO installing rpy2.

Related

AttributeError: module 'sst' has no attribute 'train_reader'

I am very new to sentiment analysis. Trying to use Stanford Sentiment Treebank(sst) and ran into an error.
from nltk.tree import Tree
import os
import sst
trees = "C:\\Users\m\data\trees"
tree, score = next(sst.train_reader(trees))
[Output]:
AttributeError Traceback (most recent call last)
<ipython-input-19-4101f90b0b16> in <module>()
----> 1 tree, score = next(sst.train_reader(trees))
AttributeError: module 'sst' has no attribute 'train_reader'
I think you're looking for https://github.com/JonathanRaiman/pytreebank, not https://pypi.org/project/sst/.
On the python side, that error is pretty clear. Once you import the right package, though, I'm not sure I saw train_reader but I could be wrong.
UPDATE:
I'm not entirely sure why you're running into the 'sst' not having the attribute train_reader. Make sure you didn't accidentally install the 'sst' package if you're using conda. It looks like the 'sst' is referring to a privately created module and that one should work.
I got your import working but what I did was I:
Installed everything specified in the requirements.txt file.
import sst was still giving me an error so I installed nltk and sklearn to resolve that issue. (fyi, im not using conda. im just using pip and virtualenv for my own private package settings. i ran pip install nltk and pip install sklearn)
At this point, import sst worked for me.
I guess you're importing the sst package selenium-simple-test, which is not what you're looking for.
Try sst.discover() , if you get the error
TypeError: discover() missing 4 required positional arguments: 'test_loader', 'package', 'dir_path', and 'names'
You are using the selenium-simple-test package

error "no module named jplephem.pck" when trying to use skyfield

I was trying to work with skyfield and I got the error that:
"ModuleNotFoundError: No module named 'jplephem.pck'"
I get the error in the first line itself
it goes like this:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-3a2b53f77cba> in <module>
----> 1 from skyfield.api import load
2
3 planets = load('de421.bsp')
4 earth, mars = planets['earth'], planets['mars']
5
~\Anaconda3\lib\site-packages\skyfield\api.py in <module>
12 from .errors import DeprecationError
13 from .iokit import Loader, load_file
---> 14 from .planetarylib import PlanetaryConstants
15 from .positionlib import position_from_radec
16 from .starlib import Star
~\Anaconda3\lib\site-packages\skyfield\planetarylib.py in <module>
3 import re
4 from numpy import array, cos, einsum, nan, rollaxis, sin
----> 5 from jplephem.pck import DAF, PCK
6 from .constants import ASEC2RAD, AU_KM, DAY_S, tau
7 from .functions import rot_x, rot_y, rot_z
ModuleNotFoundError: No module named 'jplephem.pck'
I tried to look it up on the net and it said that it is a dependency and I do not know what to do to debug this
from skyfield.api import load
planets = load('de421.bsp')
earth, mars = planets['earth'], planets['mars']
ts = load.timescale()
t = ts.now()
position = earth.at(t).observe(mars)
ra, dec, distance = position.radec()
print(ra)
print(dec)
print(distance)
Any form of help will be appreciated
Did you install Skyfield with pip install skyfield, or through another mechanism? Current versions of Skyfield have a setup.py that insists on a recent version of jplephem because only versions more recent than 2.11 will have the pck module that Skyfield needs. The pip install tool should have detected this, but if it did not, doing pip install -U jplephem to force an update of jplephem should get you going again!
Workaround
If you are using conda, you will be installing an old version. Try:
conda uninstall jplephem
pip install -U jplephem
Real solution
The long-term solution is for the conda folks to get their packaging of this library working again. The list of pull requests on their "feedstock" for the library looks like it has encountered repeated failures to build and distribute an up-to-date package:
But the most recent PR is hand-written and has asked for moderator attention, so hopefully things will get fixed.

Pytables on Enthought Python for OS X 10.8.2

I've been struggling to get pytables and the underlying HDF5 library working on python in OS X, so thought I'd give the Enthought distribution a go (which will also greatly simplify deployment across platforms later on).
I installed EPD 7.3 for 64-bit OS X (I'm running 10.8.2), but unfortunately no success, I get the following when trying to load the pytables...
In [4]: import tables
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /<ipython-input-4-389ecae14f10> in <module>()
----> 1 import tables
/Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/__init__.py in <module>()
57
58 # Necessary imports to get versions stored on the Pyrex extension
---> 59 from tables.utilsExtension import getPyTablesVersion, getHDF5Version
60
61 __version__ = getPyTablesVersion()
ImportError: dlopen(/Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so, 2): Symbol not found: _SZ_BufftoBuffCompress Referenced from: /Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so Expected in: flat namespace in /Users/davidperry/Library/Python/2.7/lib/python/site-packages/tables/utilsExtension.so
I presume this means that szip, a required library for HDF5, cannot be found? If it is actually missing from EPD (seems odd...), can I install it myself without building HDF5 from source? Or is is just in a strange place?
First, I apologize for the problems you are encountering.
It looks as if you are not loading pytables from EPD, but from a former installation. How does PYTHONPATH look like in your environment ?
Generally, EPD is installed somewhere in /Library/Frameworks/Python.framework/Versions/7.3. What does the following do ?
PYTHONPATH= /Library/Frameworks/Python.framework/Versions/7.3/bin/python -c "import tables; print tables.__version__"
or (64 bits version):
PYTHONPATH= /Library/Frameworks/EPD64.framework/Versions/7.3/bin/python -c "import tables; print tables.__version__"
It should return you something like "2.3.1" (the actual tables version available in EPD). If that indeed works, then do make EPD the default python in your environment, you will need to adapt the PATH/PYTHONPATH variables to make it available.
If that still does not work, then can you try the following (adapt for 32 bits):
PYTHONPATH= /Library/Frameworks/EPD64.framework/Versions/7.3/bin/python -c "import sys; print sys.path"
and paste the output ?

python (enthoughts distribution) - run example results in runtime error

I recently installed the enthoughts distribution of python and started to go through the examples as outlined here
http://www.enthought.com/products/epdgetstart.php?platform=mac
i.e.
EPD comes with a number of examples to get you started. To run the scripts in the Examples subdirectories, simply launch IPython and type run .
I executed the following and received a run time error which I'm not sure how to interpret as I am a new to python and enoughts.
mycomputer:demo$ ipython
In [1]: run multiaxis_using_Plot.py
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo/multiaxis_using_Plot.py in <module>()
14 from scipy.special import jn
15
---> 16 from chaco.example_support import COLOR_PALETTE
17 # Enthought library imports
18 from enable.api import Component, ComponentEditor
/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/chaco/example_support.py in <module>()
47 pass
48 else:
---> 49 raise RuntimeError("Can't load wx or qt4 backend for Chaco.")
50
51
RuntimeError: Can't load wx or qt4 backend for Chaco.
In [2]:
In [2]: pwd
Out[2]: u'/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo'
Any insights on what might be going on? I greatly appreciate it.
User 'minrk' answered this question:
As described on the 64bit EPD download page, several GUI toolkits (definitely Wx, and I think Pyglet as well) are not functional when run in 64bit mode on EPD on OS X. It is recommended that if you want to use the GUI tools on OSX, you use 32bit EPD. – minrk

wxPython import error

I'm having trouble figuring out an error message in Python.
yesterday, I've installed python using the latest EPD package, and wxPython2.9 using the wxPython2.9-osx-cocoa-py2.7 package for Mac OS.
I then added wx to my PYTHONPATH.
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa
export PYTHONPATH=$WXDIR
export PYTHONPATH=$PYTHONPATH:$WXDIR/tools
but when I try to run stuff I get this error:
In [14]: import matplotlib.pyplot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/imrisofer/Documents/third/hddm-read-only/hddm/<ipython console> in <module>()
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
93
94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, show = pylab_setup()
96
97 #docstring.copy_dedent(Artist.findobj)
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/__init__.py in pylab_setup()
23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
24 backend_mod = __import__(backend_name,
---> 25 globals(),locals(),[backend_name])
26
27 # Things we pull in from all backends
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wxagg.py in <module>()
21
22 from backend_agg import FigureCanvasAgg
---> 23 import backend_wx # already uses wxversion.ensureMinimal('2.8')
24 from backend_wx import FigureManager, FigureManagerWx, FigureCanvasWx, \
25 FigureFrameWx, DEBUG_MSG, NavigationToolbar2Wx, error_msg_wx, \
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py in <module>()
43 import wxversion
44 except ImportError:
---> 45 raise ImportError(missingwx)
46
47 # Some early versions of wxversion lack AlreadyImportedError.
ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8
I can successfully import wx, so I don't no what's the problem.
Am I missing anything in the PYTHONPATH?
In Ubuntu 12.04, this problem can be solved by running the command
sudo apt-get install libjpeg62
I realize this may not be useful here, but I wanted to document it somewhere on teh interwebz so I can find it when I run into this problem again myself which will undoubtedly happen.
I'm using Ubuntu 13.10, Canopy 1.2, and PyCharm 3.0.2. When trying to use matlablib, it always complains "Matplotlib backend_wx and backend_wxagg require wxPython >=2.8".Pretty sure that I'm using wxPython 2.8. Then I tried all the methods described in this page, but neither of them works for me.
It turns out that it can be solved by modifying matplotlibrc file. There is a line:
backend : WXAgg
In fact we can change the backend to whatever we like, and I change it to TKAgg, which works just fine for me.
Select your wx version before importing any wx modules
import wxversion
wxversion.select('2.8')
The above code should come before import wx
This happened to me on a Windows x64 installation that did not install wxversion.py in the site-packages directory (c:\Python27\Lib\site-packages by default).
You can get a copy of wxversion.py from the WX svn repository:
http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/wxversion/wxversion.py?content-type=text%2Fplain&view=co
this link helped me
https://support.enthought.com/entries/22601196-wxPython-2-8-and-2-9
Here's how I fixed the problem, which I hope will be useful for others in future
In Terminal: gedit Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
Edit the line "backend : WXAgg" into "backend : QtAgg"
Save and exit
I just ran into this myself. One potential cause of this (quite unhelpful) error message is if you installed wx as a single-version installation (INSTALL_MULTIVERSION=0 when running setup.py). In this case, the module wxversion does not get built (or installed) and as such matplotlib incorrectly assumes that all of wx is missing.
This currently is the default setting in installations by the homebrew version of wxWidgets (wxmac) with the option --python.
In your case (albeit a year and a half late), you'd need to ensure that wxversion.py exists within /usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/. If it doesn't, you'd need to recompile wx with the above flag set. Otherwise you just need to set your $PYTHONPATH such that it includes the base site-packages directory, too:
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages
export PYTHONPATH=$WXDIR:$WXDIR/wx-2.9.1-osx_cocoa:$WXDIR/wx-2.9.1-osx_cocoa/tools
I've solved with this:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I solved this by setting the backend to MacOSX in ~/.matplotlib/matplotlibrc:
backend : MacOSX
I've solved this on Windows by looking in the site packages folder in the python library. In there, there should be another folder titled site-packages. In this subfolder, there is the wxversion library. If you copy this library into the Lib folder in python, this import error should be averted.
sudo apt-get install python-wxtools
Install it. Worked for me.

Categories