在Windows7 64bit上为Python 2.7安装rpy2

时间:2012-06-22 22:49:10

标签: python windows r rpy2

我正在尝试构建和安装rpy2 Python模块。但是出现了错误(见下文)。

我已在C:\Program Files\R\R-2.15.0\安装了R,R.h位于C:\Program Files\R\R-2.15.0\include。如何告诉setup.py在该目录中找到R头?

Python和R都是使用Windows 64bit的官方二进制文件安装的。

有人可以为windows 64bit和Python2.7 64bit提供rpy2二进制构建吗? Christoph Gohlke出于法律或技术原因说,rpy2不包括在他的Unofficial Windows Binaries for Python Extension Packages中。其他人有成功的打击?

谢谢!

考虑以下过程:

$ python setup.py  build
running build
running build_py
running build_ext

returned an empty string. (5 times)

将R配置为库:

include_dirs: ()
libraries: ()
library_dirs: ('C:/PROGRA~1/R/R-215~1.0/bin/i386',)
extra_link_args: ()
 # OSX-specific (included in extra_link_args)
  framework_dirs: ()
  frameworks: ()

建立rpy2.rinterface._rinterface'扩展,使用此命令:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c 
/nologo /Ox /MD /W3 /GS- /DNDEBUG -DWin32=1 -DCSTACK_DEFNS=1 
-I.\rpy\rinterface -IC:\Python27\include -IC:\Python27\PC 
/Tc.\rpy\rinterface\_rinterface.c 
/Fobuild\temp.win-amd64-2.7\Release\.\rpy\rinterface\_rinterface.obj
_rinterface.c

给出了这个错误:

.\rpy\rinterface\_rinterface.c(61) : fatal error C1083: Cannot open include file: 
'R.h': No such file or directory
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe"' 
failed with exit status 2

6 个答案:

答案 0 :(得分:4)

这里是rpy2 Windows二进制文件的链接,所有Python版本和x86 / x64:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2

答案 1 :(得分:2)

我的经验(2.7.9(默认,2014年12月10日,12:28:03)[MSC v.1500 64 bit(AMD64)]): - 所有二进制安装程序 - 显然rpy2有未指定的依赖项 - 安装了numpy和scipy(win_amd64二进制文件)及其未指定的依赖项

  1. 安装R,安装所需的软件包
  2. 安装pywin32
  3. " pip install singledispatch"
  4. " pip install rpy2-2.5.6-cp27-none-win_amd64.whl"
  5. 更新环境,例如 os.environ [' R_HOME'] = r' C:\ Program Files \ R \ R-3.1.3' os.environ [' R_USER'] = r' C:\ Python27 \ Lib \ site-packages \ rpy2'

答案 2 :(得分:1)

我自己也在做同样的事情。库等位于表明你正在拿起32位版本的i386。添加“C:\ Program Files \ R \ R-2.15.1 \ include”include目录可能有助于强制解决问题。这是我得到的最远的:

building 'rpy2.rinterface._rinterface' extension
error: Unable to find vcvarsall.bat

使用MSVC express shell并在路径中使用R x64和msys。

答案 3 :(得分:1)

这个二进制文件的链接对我有用,我希望其他人觉得它很有用: link to the binary

答案 4 :(得分:1)

我在Windows 10上尝试了所有这些并且无处可去。当我执行import rpy时,它说它已经安装到我已经使用了几个月的Anaconda版本中,但是当我尝试git时,它只是出错了。

要放弃,但后来我睡了一晚,然后我从命令行做了以下事情:

  • 删除了所有旧的Python实例,包括Anaconda
  • 重新启动
  • 重新安装Anaconda(2.4.1,Python版本2.7.11)
  • 确保python从任何目录的命令行运行
  • 启动了我的“mingw32”bash shell(R_HOME附带的那个)
  • 将我的个人C:\Program Files\R\R-3.2.3环境变量设置为rpy2-2.7.5-cp27-none-win_amd64.whl
  • 按上述建议从http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2下载Downloads
  • 将工作目录更改为我的用户pip install rpy2-2.7.5-cp27-none-win_amd64.whl目录
  • 使用mwise@MWISE-OPTO ~/Downloads $ pip install rpy2-2.7.5-cp27-none-win_amd64.whl Processing c:\users\mwise\downloads\rpy2-2.7.5-cp27-none-win_amd64.whl Requirement already satisfied (use --upgrade to upgrade): six in c:\users\mwise\appdata\local\continuum\anaconda2\lib\site-packages (from rpy2==2.7.5) Requirement already satisfied (use --upgrade to upgrade): singledispatch in c:\users\mwise\appdata\local\continuum\anaconda2\lib\site-packages (from rpy2==2.7.5 ) Installing collected packages: rpy2 Successfully installed rpy2-2.7.5 mwise@MWISE-OPTO ~/Downloads $ python Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec 7 2015, 14:10:42) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> import rpy2 >>> import rpy2.robjects as robjects >>> pi = robjects.r['pi'] >>> pi[0] 3.141592653589793 >>>
  • 安装
  • 启动python并成功导入并使用了py2

以下是最后步骤的截屏:

let entityDescription = NSEntityDescription.entityForName("FoodItem", inManagedObjectContext: self.managedObjectContext)

    let localFoodItem = NSManagedObject(entity: entityDescription!, insertIntoManagedObjectContext: self.managedObjectContext)

    let syncpredicate = NSPredicate(value: true)

    let syncquery = CKQuery(recordType: "Food", predicate: syncpredicate)

publicDatabase.performQuery(syncquery, inZoneWithID: nil) { results, error in
        if error == nil { // There is no error
            var numberAdded = 0
            for entry in results! {

                let cloudUPC = entry["UPC"] as? String
                //print("UPC from CloudKit \(cloudUPC)")
                let cloudFoodName = entry["foodName"] as? String
                //print("Name from CloudKit \(cloudFoodName)")
                let cloudIngredients = entry["ingredients"] as? String
                //print("Ingredients from CloudKit \(cloudFoodName)")
                numberAdded++


                let corepredicate = NSPredicate(format: "upc = %@", cloudUPC!)


                // Initialize Fetch Request
                let fetchRequest = NSFetchRequest()

                fetchRequest.predicate = corepredicate
                fetchRequest.entity = entityDescription

                var error: NSError?

                do {
                    let result = try self.managedObjectContext.executeFetchRequest(fetchRequest)


                    if result.count > 0 {
                        let match = result[0] as! NSManagedObject
                        print("FoodItem Found in CoreData")
                        let upcNumber = match.valueForKey("upc") as! String


                        let iList = match.valueForKey("ingredients") as! String



                        let coreName = match.valueForKey("productName") as! String

print("Item UPDATED in CoreData")
                            localFoodItem.setValue(cloudUPC, forKey: "upc")
                            localFoodItem.setValue(cloudFoodName, forKey: "productName")
                            localFoodItem.setValue(cloudIngredients, forKey: "ingredients")


                    } else {
                        print("IMPORTED New Item from CloudKit")
                        localFoodItem.setValue(cloudUPC, forKey: "upc")
                        localFoodItem.setValue(cloudFoodName, forKey: "productName")
                        localFoodItem.setValue(cloudIngredients, forKey: "ingredients")
                        //print("Record Update: \(numberAdded)")
                    }


                } catch let error as NSError {
                    // failure
                    print("Fetch failed: \(error.localizedDescription)")
                }


            do {
                try self.managedObjectContext.save()
            } catch {
                print(error)
            }
            }
            print("Database Additions: \(numberAdded)")
        }else {
            print(error)
        }

    }

希望这会有所帮助......

答案 5 :(得分:-1)

这是因为您的R包含库不在您的CPPFLAGS环境变量中。 您应该在" C:\ Program Files \ R \ R-2.15.0 \ include"中找到文件R.h. 在linux中,您可以将其添加到.bashrc

export "$CPPFLAGS=-I/path-to-R/include $CPPFLAGS"

但是我并不熟悉Windows中的python和R. 这就是我所能提供的一切。