- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Python(和一般编程)的新手,我有金融背景,所以请多多包涵。我刚开始使用 Python(Enthought 的 Pylab/Scipy/Numpy)和 R 进行统计分析。我正在尝试将 rpy2 安装到 Python 中以集成 R,但出现错误:
Tried to guess R's HOME but no R command in the PATH.
我不确定这是什么意思。如果有用的话,我的 R.exe 的路径是“C:\Program Files\R\R-2.12.1\bin”。任何帮助将不胜感激!
这是setup.py的代码
import os, os.path, sys, shutil, re, itertools
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.build import build as _build
from distutils.core import setup
from distutils.core import Extension
pack_name = 'rpy2'
pack_version = __import__('rpy').__version__
class build(_build):
user_options = _build.user_options + \
[
#('r-autoconfig', None,
# "guess all configuration paths from " +\
# "the R executable found in the PATH " +\
# "(this overrides r-home)"),
('r-home=', None,
"full path for the R home to compile against " +\
"(see r-autoconfig for an automatic configuration)"),
('r-home-lib=', None,
"full path for the R shared lib/ directory " +\
"(<r-home>/lib otherwise)"),
('r-home-modules=', None,
"full path for the R shared modules/ directory " +\
"(<r-home>/modules otherwise)")
]
boolean_options = _build.boolean_options #+ \
#['r-autoconfig', ]
def initialize_options(self):
_build.initialize_options(self)
self.r_autoconfig = None
self.r_home = None
self.r_home_lib = None
self.r_home_modules = None
class build_ext(_build_ext):
"""
-DRPY_VERBOSE
-DRPY_DEBUG_PRESERV
-DRPY_DEBUG_PROMISE : evaluation of promises
-DRPY_DEBUG_OBJECTINIT : initialization of PySexpObject
-DRPY_DEBUG_CONSOLE : console I/O
-DRPY_DEBUG_COBJECT : SexpObject passed as a CObject
-DRPY_DEBUG_GRDEV
"""
user_options = _build_ext.user_options + \
[
#('r-autoconfig', None,
# "guess all configuration paths from " +\
# "the R executable found in the PATH " +\
# "(this overrides r-home)"),
('r-home=', None,
"full path for the R home to compile against " +\
"(see r-autoconfig for an automatic configuration)"),
('r-home-lib=', None,
"full path for the R shared lib/ directory" +\
"(<r-home>/lib otherwise)"),
('r-home-modules=', None,
"full path for the R shared modules/ directory" +\
"(<r-home>/modules otherwise)")]
boolean_options = _build_ext.boolean_options #+ \
#['r-autoconfig', ]
def initialize_options(self):
_build_ext.initialize_options(self)
self.r_autoconfig = None
self.r_home = None
self.r_home_lib = None
self.r_home_modules = None
def finalize_options(self):
self.set_undefined_options('build',
#('r_autoconfig', 'r_autoconfig'),
('r_home', 'r_home'))
_build_ext.finalize_options(self)
if self.r_home is None:
self.r_home = os.popen("R RHOME").readlines()
if len(self.r_home) == 0:
raise SystemExit("Error: Tried to guess R's HOME but no R command in the PATH.")
#Twist if 'R RHOME' spits out a warning
if self.r_home[0].startswith("WARNING"):
self.r_home = self.r_home[1]
else:
self.r_home = self.r_home[0]
#self.r_home = [self.r_home, ]
if self.r_home is None:
raise SystemExit("Error: --r-home not specified.")
else:
self.r_home = self.r_home.split(os.pathsep)
rversions = []
for r_home in self.r_home:
r_home = r_home.strip()
rversion = get_rversion(r_home)
if cmp_version(rversion[:2], [2, 8]) == -1:
raise SystemExit("Error: R >= 2.8 required.")
rversions.append(rversion)
config = RConfig()
for about in ('--ldflags', '--cppflags',
'LAPACK_LIBS', 'BLAS_LIBS'):
config += get_rconfig(r_home, about)
print(config.__repr__())
self.include_dirs.extend(config._include_dirs)
self.libraries.extend(config._libraries)
self.library_dirs.extend(config._library_dirs)
if self.r_home_modules is None:
self.library_dirs.extend([os.path.join(r_home, 'modules'), ])
else:
self.library_dirs.extends([self.r_home_modules, ])
#for e in self.extensions:
# self.extra_link_args.extra_link_args(config.extra_link_args)
# e.extra_compile_args.extend(extra_compile_args)
def run(self):
_build_ext.run(self)
def get_rversion(r_home):
r_exec = os.path.join(r_home, 'bin', 'R')
# Twist if Win32
if sys.platform == "win32":
rp = os.popen3('"'+r_exec+'" --version')[2]
else:
rp = os.popen('"'+r_exec+'" --version')
rversion = rp.readline()
#Twist if 'R RHOME' spits out a warning
if rversion.startswith("WARNING"):
rversion = rp.readline()
m = re.match('^R version ([^ ]+) .+$', rversion)
rversion = m.groups()[0]
rversion = rversion.split('.')
rversion[0] = int(rversion[0])
rversion[1] = int(rversion[1])
return rversion
def cmp_version(x, y):
if (x[0] < y[0]):
return -1
if (x[0] > y[0]):
return 1
if (x[0] == y[0]):
if len(x) == 1 or len(y) == 1:
return 0
return cmp_version(x[1:], y[1:])
class RConfig(object):
_include_dirs = None
_libraries = None
_library_dirs = None
_extra_link_args = None
_frameworks = None
_framework_dirs = None
def __init__(self,
include_dirs = tuple(), libraries = tuple(),
library_dirs = tuple(), extra_link_args = tuple(),
frameworks = tuple(),
framework_dirs = tuple()):
for k in ('include_dirs', 'libraries',
'library_dirs', 'extra_link_args'):
v = locals()[k]
if not isinstance(v, tuple):
if isinstance(v, str):
v = [v, ]
v = tuple(set(v))
self.__dict__['_'+k] = v
# frameworks are specific to OSX
for k in ('framework_dirs', 'frameworks'):
v = locals()[k]
if not isinstance(v, tuple):
if isinstance(v, str):
v = [v, ]
v = tuple(set(v))
self.__dict__['_'+k] = v
self.__dict__['_'+'extra_link_args'] = tuple(set(v + self.__dict__['_'+'extra_link_args']))
def __repr__(self):
s = 'Configuration for R as a library:' + os.linesep
s += os.linesep.join(
[' ' + x + ': ' + self.__dict__['_'+x].__repr__() \
for x in ('include_dirs', 'libraries',
'library_dirs', 'extra_link_args')])
s += os.linesep + ' # OSX-specific (included in extra_link_args)' + os.linesep
s += os.linesep.join(
[' ' + x + ': ' + self.__dict__['_'+x].__repr__() \
for x in ('framework_dirs', 'frameworks')]
)
return s
def __add__(self, config):
assert isinstance(config, RConfig)
res = RConfig(include_dirs = self._include_dirs + \
config._include_dirs,
libraries = self._libraries + config._libraries,
library_dirs = self._library_dirs + \
config._library_dirs,
extra_link_args = self._extra_link_args + \
config._extra_link_args)
return res
@staticmethod
def from_string(string, allow_empty = False):
possible_patterns = ('^-L(?P<library_dirs>[^ ]+)$',
'^-l(?P<libraries>[^ ]+)$',
'^-I(?P<include_dirs>[^ ]+)$',
'^(?P<framework_dirs>-F[^ ]+?)$',
'^(?P<frameworks>-framework [^ ]+)$')
pp = [re.compile(x) for x in possible_patterns]
# sanity check of what is returned into rconfig
rconfig_m = None
span = (0, 0)
rc = RConfig()
for substring in re.split('(?<!-framework) ', string):
ok = False
for pattern in pp:
rconfig_m = pattern.match(substring)
if rconfig_m is not None:
rc += RConfig(**rconfig_m.groupdict())
span = rconfig_m.span()
ok = True
break
elif rconfig_m is None:
if allow_empty and (rconfig == ''):
print(cmd + '\nreturned an empty string.\n')
rc += RConfig()
ok = True
break
else:
# if the configuration points to an existing library,
# use it
if os.path.exists(string):
rc += RConfig(library = substring)
ok = True
break
if not ok:
raise ValueError('Invalid substring\n' + substring
+ '\nin string\n' + string)
return rc
def get_rconfig(r_home, about, allow_empty = False):
r_exec = os.path.join(r_home, 'bin', 'R')
cmd = '"'+r_exec+'" CMD config '+about
rp = os.popen(cmd)
rconfig = rp.readline()
#Twist if 'R RHOME' spits out a warning
if rconfig.startswith("WARNING"):
rconfig = rp.readline()
rconfig = rconfig.strip()
rc = RConfig.from_string(rconfig)
return rc
def getRinterface_ext():
#r_libs = [os.path.join(RHOME, 'lib'), os.path.join(RHOME, 'modules')]
r_libs = []
extra_link_args = []
#FIXME: crude way (will break in many cases)
#check how to get how to have a configure step
define_macros = []
if sys.platform == 'win32':
define_macros.append(('Win32', 1))
else:
define_macros.append(('R_INTERFACE_PTRS', 1))
define_macros.append(('HAVE_POSIX_SIGJMP', 1))
define_macros.append(('CSTACK_DEFNS', 1))
define_macros.append(('RIF_HAS_RSIGHAND', 1))
include_dirs = []
rinterface_ext = Extension(
name = pack_name + '.rinterface.rinterface',
sources = [ \
#os.path.join('rpy', 'rinterface', 'embeddedr.c'),
#os.path.join('rpy', 'rinterface', 'r_utils.c'),
#os.path.join('rpy', 'rinterface', 'buffer.c'),
#os.path.join('rpy', 'rinterface', 'sequence.c'),
#os.path.join('rpy', 'rinterface', 'sexp.c'),
os.path.join('rpy', 'rinterface', 'rinterface.c')
],
depends = [os.path.join('rpy', 'rinterface', 'embeddedr.h'),
os.path.join('rpy', 'rinterface', 'r_utils.h'),
os.path.join('rpy', 'rinterface', 'buffer.h'),
os.path.join('rpy', 'rinterface', 'sequence.h'),
os.path.join('rpy', 'rinterface', 'sexp.h'),
os.path.join('rpy', 'rinterface', 'rpy_rinterface.h')
],
include_dirs = [os.path.join('rpy', 'rinterface'),] + include_dirs,
libraries = ['R', ],
library_dirs = r_libs,
define_macros = define_macros,
runtime_library_dirs = r_libs,
#extra_compile_args=['-O0', '-g'],
#extra_link_args = extra_link_args
)
rpy_device_ext = Extension(
pack_name + '.rinterface.rpy_device',
[
os.path.join('rpy', 'rinterface', 'rpy_device.c'),
],
include_dirs = include_dirs +
[os.path.join('rpy', 'rinterface'), ],
libraries = ['R', ],
library_dirs = r_libs,
define_macros = define_macros,
runtime_library_dirs = r_libs,
#extra_compile_args=['-O0', '-g'],
extra_link_args = extra_link_args
)
return [rinterface_ext, rpy_device_ext]
rinterface_exts = []
ri_ext = getRinterface_ext()
rinterface_exts.append(ri_ext)
pack_dir = {pack_name: 'rpy'}
import distutils.command.install
for scheme in distutils.command.install.INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']
setup(
#install_requires=['distribute'],
cmdclass = {'build': build,
'build_ext': build_ext},
name = pack_name,
version = pack_version,
description = "Python interface to the R language",
url = "http://rpy.sourceforge.net",
license = "AGPLv3.0 (except rpy2.rinterface: LGPL)",
author = "Laurent Gautier",
author_email = "lgautier@gmail.com",
ext_modules = rinterface_exts[0],
package_dir = pack_dir,
packages = [pack_name,
pack_name + '.rlike',
pack_name + '.rlike.tests',
pack_name + '.rinterface',
pack_name + '.rinterface.tests',
pack_name + '.robjects',
pack_name + '.robjects.tests',
pack_name + '.robjects.lib',
],
classifiers = ['Programming Language :: Python',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'License :: OSI Approved :: GNU Affero General Public License v3',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Development Status :: 5 - Production/Stable'
],
data_files = [(os.path.join('rpy2', 'images'),
[os.path.join('doc', 'source', 'rpy2_logo.png')])]
#[pack_name + '.rinterface_' + x for x in rinterface_rversions] + \
#[pack_name + '.rinterface_' + x + '.tests' for x in rinterface_rversions]
)
最佳答案
我知道我参加派对有点晚了,但我遇到了同样的问题,通过 conda 安装它可以在 Windows 7 上运行
conda install --channel https://conda.binstar.org/joshadel rpy2
关于python - 在 win7(R 2.12,Python 2.5)上安装 rpy2 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4924917/
我听说最好不要从您系统的 Perl 版本所在的 CPAN 安装模块。我知道如何使用命令行安装模块,我只是想知道是否有办法将 CPAN 与系统核心 Perl 分开。 我应该: 下载源代码并专门为这些模块
我听说最好不要从系统的 Perl 版本所在的 CPAN 安装模块。我知道如何使用命令行安装模块,我只是想知道是否有办法将 CPAN 与系统的核心 Perl 分开。 我应该: 下载源代码并专门为这些模块
单独安装 electron 与通过 electron-builder 安装有什么区别?我正在使用 React 构建一个 Electron 应用程序,并且已经找到了一些教程。它们安装 Electron
两者安装有什么区别?我按照安装页面上的说明在全局范围内安装了 webpack,然后我转到了入门指南,据说在那里可以在本地安装 webpack-cli。 CLI = Command Line Inter
我在 OS X Yosemite 上用 PHP 安装了默认的 Apache 服务器,安装了 pear,用 brew 安装了 Solr (brew install solr),现在我正在尝试使用 PEC
我解压并编译了 Ruby 2.1 并安装了几个支持工具。 但是当我安装了 libssl-dev 时,OpenSSL 不会安装。 我在支持 openssl 时遇到这个错误: make: *** No r
我在 android studio 2.3.1 和 gradle 3.2 中设计了 2 到 3 个应用程序。当我从它运行应用程序到任何设备或模拟器时,一切都工作正常。但是当我从构建文件夹中获取该 ap
我注意到我正在读一本书提到通过 apt-get 安装 numpy 和 opencv apt-get install python-numpy python-opencv 但我可以通过以下方式在 pip
我正在尝试在 Windows 8.1 上安装 ansicon。我提取了文件并达到了我需要调用 ansicon -i 的级别。当我在 cmd 中输入此内容并运行 python 脚本时效果很好,但是当我通
我有 linux MINT 17.3 Kernel 4.4.0-81 所有更新可用。 (由于不同的原因,我无法迁移到更新版本的 ubuntu/mint) 我已经通过 PPA 安装了 FFMPEG(不是
尝试在本地运行我的应用程序时出现错误: 我只在 chrome 浏览器中收到此错误。我尝试过不同的东西,但我不确定为什么它是 Chrome 特定的。 最佳答案 我怀疑这不是 Firebase 问题,而是
这是我第一次开发 AngularJS 应用程序并使用脚手架工具 Yeoman ( http://yeoman.io/ )。我想对我的一些图标使用 fontawesome ( http://fortaw
我知道您通常“应该”$ pip install 如果包没有 brew ,但如果有一个你想安装的 python 包,你可以使用 $ pip install或 $ brew install为了?例如,通过
我正在尝试通过 RVM 安装 Ruby 1.9.3。然而,当谈到安装 RubyGems 时,我得到了这个: curl: (22) The requested URL returned error: 4
我是真正提出问题的新手,但你去吧。 我一直在尝试按照安装指南添加 dnsname: https://github.com/containers/dnsname https://github.com/c
Studio更新至0.4.0 建筑产量为“需要1.8版Gradle”;将设置设置为1.8 bin目录; 建立 “要求1.9级”;将设置设置为1.9 bin; 建立 “要求1.8级” 啊。不知道该怎么做
我刚刚注意到 kernel.org 因维护而停机。是否有使用不同镜子的不同公式?或者我可以向 Homebrew 软件添加不同的来源(如 bundler ?)? 谢谢你的帮助! 最佳答案 快速解决方法:
当我运行时: peardev install phpunit/PHPUnit 我得到以下信息: No releases available for package "pear.phpunit.de/P
服务器操作系统为Fedora 24. 64bit。 我想安装 Git 2.6.6。 所以下载源码并安装。 此服务器离线。所以我不使用“yum”。 ./configure --prefix=/usr/l
我正在尝试在我自己的服务器(操作系统:Linux Ubuntu Server 12.04)上安装 OpenEdX,但我遇到了同样的错误。谁能帮帮我? TASK: [ insights | insta
我是一名优秀的程序员,十分优秀!