Error - cannot install Miniconda with RStudio - python

I have written a R script where I use some python lines through the reticulate package.
I need to share it with some colleagues who don't know about programming and I've created a batch file so I can run it without them even opening R.
However, I tried using the install_miniconda() function to silently install python to run the code without them knowing (I guess people are reluctant to installing a couple of programs) but R throws an error:
> reticulate::install_miniconda(path="C:/")
# * Installing Miniconda -- please wait a moment ...
# * Downloading "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" ...
# trying URL 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe'
# Content type 'application/octet-stream' length 74687656 bytes (71.2 MB)
# downloaded 71.2 MB
# Error: Miniconda installation failed [unknown reason]
I tried without passing any path but my computer user has spaces on it so I cannot use it, that's why I resorted to supplying it with the root path "C:/"
Can someone help me understand what is happening?
Note: I am using R 4.2.1 on Windows 11 (also tried on Windows 10 with the same result)

Try installing rminiconda from the github like this:
remotes::install_github("hafen/rminiconda")
rminiconda::install_miniconda(name='your_name')
After that you can specify the installation using reticulate like this:
py <- rminiconda::find_miniconda_python("your_name")
reticulate::use_python(py, required = TRUE)

Related

Not able to install umx packaging in R 3.6.3

I updated my R to the most recent version 4.0 and tried to install the 'umx' package which worked fine when I had the 3.6.3 version. I then changed my R back to 3.6.3 version and the 'umx' package still won't install. I get the below error:
installing source package ‘kableExtra’ ...
** package ‘kableExtra’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/gdtools/libs/gdtools.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/gdtools/libs/gdtools.so, 6): Library not loaded: /opt/X11/lib/libcairo.2.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/gdtools/libs/gdtools.so
Reason: image not found
Calls: ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted
ERROR: lazy loading failed for package ‘kableExtra’
removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/kableExtra’
Warning in install.packages :
installation of package ‘kableExtra’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/88/d4_sv_l174vcbkn5f8r6ytjc0000gn/T/RtmpSb59yk/downloaded_packages’
Not sure why this is as everything was fine before I updated my R, and my expectation was that it would be fine again when going back to my original R version but this is not the case. Any help with this would be greatly appreciated!
Thanks,
Rionagh
I was getting the same error for the last 2 days and then I wrote an issue in GitHub to the person who made this package. One of people answered my question by suggesting to update the version of R. Same like you, I was using 3.6.2 version of R and then I followed his suggestion, I updated my R version to 4.0.4 He also suggested me to upload "systemfonts" package before I upload the kableExtra by writing this code install.packages('systemfonts', dependencies = TRUE). Yet I think it was because of the old version that ı was using. So the bottomline is, if you update your R to 4.0.4, and run these 2 codes;
install.packages('systemfonts', dependencies = TRUE)
install.packages('kableExtra', repos='https://cran.ma.imperial.ac.uk/')
it is just going to work I guess. I mean it worked for me.

Python Reticulate not working in Rstudio Cloud

I am a big fan of Rstudio Cloud and would like to inter-grate R and Python by using the package Reticulate.
It looks like Rstudio Cloud is using python 2.7 (no problems with that). When I try to write Python Code in an R markdown document, nothing gets run.
---
title: "reticulate"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(reticulate)
py_config()
```
```{python}
import pandas
x = 4
```
Python code does not get run.
I am also finding that if I want to install python packages in an R script using reticulate. I have to create a virtual environment. What is the reason behind that?
library(reticulate)
virtualenv_create("r-reticulate")
virtualenv_install("r-reticulate", "scipy")
virtualenv_install("r-reticulate", "pandas")
If I use conda_install, I get an error message.
conda_create("r-reticulate")
Error: Unable to find conda binary. Is Anaconda installed?
conda_install("r-reticulate", "scipy")
Error: Unable to find conda binary. Is Anaconda installed?
The goal is to have python working in Rstudio cloud on R markdown. I can not install packages and execute code.
I just succeeded in getting Conda installed in Rstudio cloud after receiving the same error message as you1, so thought I'd share how I got this working.
I created two scripts:
to install miniconda (i think that's the step you're missing, and why Conda didn't work for you) and then restartSession for this to be accessible
to seperately store the commands for setting up Conda, with the running of this script passed as a command to the call to restartSession (because otherwise the commands are triggered before R has restarted, and they fail; sys.sleep() didn't seem to work, but this method did)
setup.R
setwd("/cloud/project") # to ensure students get required resources
install.packages("rstudioapi") # to restart R session w/ installations
install.packages("reticulate") # for python
reticulate::install_miniconda("miniconda") # for python
# Restart again to make sure all system things are loaded
# and then create a new Conda environment
rstudioapi::restartSession(command="source('nested_reticulate_setup.R')")
nested_reticulate_setup.R
reticulate::conda_create("r-reticulate")
reticulate::conda_install("r-reticulate", "scipy")
Sys.setenv(RETICULATE_PYTHON="/cloud/project/miniconda/envs/r-reticulate/bin/python")
reticulate::use_condaenv("r-reticulate")
osmnx <- reticulate::import("scipy")
Then if you make a call to scipy, eg scicpy$`__version__` , I believe it should work for you without that error you observed.
I couldn't find a solution to this issue elsewhere, so thought it worth responding to this old post in case it helps somebody some day. I am sure there are other ways of approaching this.
1 Perhaps for a different reason; i'll explain later in the post...

MLWIC: Machine Learning for Wildlife Image Classification in R Issues with Python

I am a wildlife PhD researcher manually identifying ~1.5 million game camera photos by species. A machine learning package in R has recently come out of a research project and I've been trying to get the script to run in R for about 12 hours and can't seem to get it right (I have used R and python a lot, but I am no expert and this is the first question I have asked on here so forgive me if I haven't done this correctly).
The ReadMe (To understand what I am trying to do you will probably have to read this, I apologize) for the package downloaded on Github is located at: https://github.com/mikeyEcology/MLWIC/blob/master/README.md
Unfortunately for me, the package was developed on a Macintosh platform and I have Windows.
I followed the steps in the ReadMe as follows:
1: Installed the MLWIC package using the code:
devtools::install_github("mikeyEcology/MLWIC")
library(MLWIC)
2: Followed the instructions to install "pip", python, and "TensorFlow" at
https://www.tensorflow.org/install/pip
3: Downloaded the L1 folder
4: I ran a different code than outlined in the ReadMe, it is as follows:
setup(python_loc = "I used this location I got from running "where python" in Anaconda")
After this initial setup, I ran the code for the "classify function":
library(MLWIC)
setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)
setwd("C:/Users/werdel/Desktop/MachineLearning")
help("classify")
classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images",# this is the absolute path to the images.
data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", # this is the location of the csv containing image information. It has Unix linebreaks and no headers.
model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is where you stored the L1 folder in Step 3 of the instructions: github.com/mikeyEcology/MLWIC/blob/master/README
python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python on your computer.
save_predictions = "model_predictions.txt" # this is the default and you should use it unless you have reason otherwise.)
This is where the problem seemed to arise. It seems to run fine, with the output showing a file created in my working directory, but when I check, there is no file. I have tried changing python location, downloading new and old versions of anaconda, messing with environments, but nothing has changed the fact that there is no file created in my working directory:
> library(MLWIC)
> setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)
Remove all packages in environment C:\PROGRA~3\ANACON~1\envs\r-reticulate:
## Package Plan ##
environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate
The following packages will be REMOVED:
ca-certificates: 2018.03.07-0
certifi: 2018.10.15-py37_0
openssl: 1.1.1a-he774522_0
pip: 18.1-py37_0
python: 3.7.1-he44a216_5
setuptools: 40.6.2-py37_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_0
wheel: 0.32.3-py37_0
wincertstore: 0.2-py37_0
Solving environment: ...working... done
## Package Plan ##
environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate
added / updated specs:
- python
The following NEW packages will be INSTALLED:
ca-certificates: 2018.03.07-0
certifi: 2018.10.15-py37_0
openssl: 1.1.1a-he774522_0
pip: 18.1-py37_0
python: 3.7.1-he44a216_5
setuptools: 40.6.2-py37_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_0
wheel: 0.32.3-py37_0
wincertstore: 0.2-py37_0
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use:
# > activate r-reticulate
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
Solving environment: ...working... failed
UnsatisfiableError: The following specifications were found to be in conflict:
- argparse
- tensorflow
Use "conda info <package>" to see the dependencies for each package.
Error: Error 1 occurred installing packages into conda environment r-reticulate
> classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images", # this is
the absolute path to the images.
+ data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", #
this is the location of the csv containing image information. It has Unix linebreaks
and no headers.
+ model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is
where you stored the L1 folder in Step 3 of the instructions:
github.com/mikeyEcology/MLWIC/blob/master/README
+ python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python
on your computer.
+ save_predictions = "model_predictions.txt" # this is the default and you
should use it unless you have reason otherwise.
+ )
[1] "evaluation of images took 0.000504970550537109 secs. The results are stored in
C:/Users/werdel/Desktop/MachineLearning/L1/model_predictions.txt. To view the results
in a viewer-friendly format, please use the function make_output"
So my final question is, does it seem like I set something up wrong while downloading pip, tensorflow, anaconda, and python, is it something with the way I am coding, etc.?
If I am not mistaken there is a small bug in their code that ignores the "data_info" path. Try renaming your "image_labels.csv" to "data_info.csv" and put the file inside the model_dir. This solved the problem for me. Also, use "C:/ProgramData/Anaconda3/" instead of "C:/ProgramData/Anaconda3/python.exe"
I was able to get MLWIC to run relatively pain-free on Mac. Getting it running on windows was a little more frustrating. I followed issue threads #6 and #13 on the MLWIC github page. On a machine running Windows 10 I downloaded Anaconda 3 5.2.0 which includes python 3.6.5. After many hours of troubleshooting I got it to work.
Once Anaconda is installed I used Anaconda Navigator to install tensorflow 1.11.0, cuddn 6.0, setuptools 40.6.2. Note this is the only place that I installed tensorflow. I did not bother with the pip install as mentioned on the tensorflow web page.
From there when first opening R I installed the following packages MLWIC, keras, cloudml, Rcpp, and reticulate. Then ran them with the library function. Also as Faisal Ahmed stated above rename image_labels.csv to data_info.csv, and move that file to the L1 folder. From here I was able to get the MLWIC provided code to run on windows. When I first ran the setup function it looked like this setup(python_loc = "C:/Users/kvanatta/Anaconda3/python")
Note: I was originally trying to get MLWIC to run with the files saved on the server in my office (S: drive) and could not get it to work. Upon transferring the files to a 1tb external hard drive (F: drive) everything worked fine from the new location.
I also downloaded the program notepad ++ to be able to convert the data_info.csv file to unix(lf) linebreaks. I believe since windows does not use these linebreaks, opening the .csv file in excel will change the line breaks. You can use notepad ++ to change them back.
Hope this helps ease some frustrations.
Cheers
I really struggled to get MLWIC working on my Windows computer and followed a number of the issues on the MLWIC github page until I came up with a solution that worked for me.
I wrote up a guide for windows users and it's been added to the MLWIC_examples repo. You can find it here. It is a step-by-step guide.
As as aside, I found a way to use Unix-type linebreaks without leaving the R environment:
# Write to UNIX type doc (required)
output.file <- file("L1\\data_info.csv", "wb")
write.table(data_info,
row.names = FALSE,
col.names = FALSE,
file = output.file,
quote = FALSE,
append = TRUE,
sep = ",")
close(output.file)
rm(output.file)

How to judge which version of .whl file is supported when install a Python package

Recently, I just try to connect my SQL Server in python. So I just download the .whl file from "http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql".
in cmd windows, I use the following command:
pip install some-package.whl
My pc is window 64bit, I tried all the .whl files in the following.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql
pymssql‑1.0.3‑cp27‑none‑win32.whl
pymssql‑2.1.3‑cp27‑cp27m‑win32.whl
pymssql‑2.1.3‑cp27‑cp27m‑win_amd64.whl
pymssql‑2.1.3‑cp34‑cp34m‑win32.whl
pymssql‑2.1.3‑cp34‑cp34m‑win_amd64.whl
pymssql‑2.1.3‑cp35‑cp35m‑win32.whl
pymssql‑2.1.3‑cp35‑cp35m‑win_amd64.whl
pymssql‑2.1.3‑cp36‑cp36m‑win32.whl
pymssql‑2.1.3‑cp36‑cp36m‑win_amd64.whl
But failed to install, with the error message, the .whl file is not supported in this system. what should I do. Can somebody help me.
The simplest procedure that helped me is:
Step 1: Open cmd as an administrator
Step 2: Type python and press Enter
You will get something like this
Here, you can see your Python version and the CPU Architecture
Step 3: Go on https://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql and select .whl file that support both, python version and also the CPU architecture. i.e. the supported file for me will be pymssql‑2.2.2‑cp39‑cp39‑win_amd64.whl where cp39 means the python version that is 3.9 in my case, and amd64 is the CPU architecture.
Step 4: Go the folder where you have downloaded the required file and in the address bar type cmd or you can open cmd as an admin and move to the download directory
Step 5: Copy name of the required downloaded file along with extension and Run the following command
pip install pymssql‑2.2.2‑cp39‑cp39‑win_amd64.whl
That's all. You can use this method for any file from this website. This method is working for me perfectly
I faced the same issue. It goes with version of Python installed on your system if it is 32 bit Python Version or 64 bit Python.
So cp36 as I have python 3.6 and win32 as Python is 32 bit according to my system.
I worked for me.
I hope this helps.
whl naming structure:
{distribution}-{version}(-{build tag})?-{python tag}-{abi
tag}-{platform tag}.whl
in your case you need to know your python --version (python tag cp27 for python2.7 etc) and your cpu architecture .
Faced the same issue,
All you need to do is change the name of your whl file:
Change up to the installed python distribution
Then none for the python version and any for the platform
Should be something like
pymssql‑2.1.3‑cp3‑none‑eny.whl
You can do this using packaging.
pip install packaging
You can use this simple function compatible_wheels I wrote using packaging to filter out for the compatible wheels for your system:
from packaging.tags import sys_tags
def parse_tag(wheel_filename):
"""
Example:
>>> parse_tag('pymssql-2.2.1-cp36-cp36m-manylinux2010_i686.whl')
'cp36-cp36m-manylinux2010_i686'
"""
return '-'.join(wheel_filename.split('-')[2:])[:-4]
def compatible_wheels(wheel_filenames):
tags = [str(tag) for tag in sys_tags()]
return [
f
for f in wheel_filenames
if parse_tag(f) in tags
]
Example usage
>>> wheel_filenames = [
'pymssql-2.2.1-cp36-cp36m-manylinux2010_i686.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux2014_i686.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux1_i686.whl',
'pymssql-2.2.1-cp39-cp39-manylinux2014_i686.whl',
'pymssql-2.2.1-cp37-cp37m-win32.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux_2_24_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux2010_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux2014_i686.whl',
'pymssql-2.2.1-cp38-cp38-manylinux2014_i686.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux_2_24_i686.whl',
'pymssql-2.2.1-cp38-cp38-macosx_10_14_x86_64.whl',
'pymssql-2.2.1-cp38-cp38-manylinux2014_x86_64.whl',
'pymssql-2.2.1-cp38-cp38-win_amd64.whl',
'pymssql-2.2.1-cp39-cp39-win32.whl',
'pymssql-2.2.1-cp39-cp39-manylinux_2_24_x86_64.whl',
'pymssql-2.2.1-cp39-cp39-win_amd64.whl',
'pymssql-2.2.1-cp39-cp39-manylinux2014_x86_64.whl',
'pymssql-2.2.1-cp38-cp38-manylinux2010_x86_64.whl',
'pymssql-2.2.1-cp38-cp38-manylinux_2_24_x86_64.whl',
'pymssql-2.2.1-cp38-cp38-win32.whl',
'pymssql-2.2.1-cp39-cp39-manylinux2010_i686.whl',
'pymssql-2.2.1-cp39-cp39-manylinux_2_24_i686.whl',
'pymssql-2.2.1-cp37-cp37m-macosx_10_14_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux2010_i686.whl',
'pymssql-2.2.1-cp38-cp38-manylinux1_i686.whl',
'pymssql-2.2.1-cp38-cp38-manylinux_2_24_i686.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux2014_x86_64.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux2010_x86_64.whl',
'pymssql-2.2.1-cp39-cp39-manylinux1_x86_64.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux1_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux1_x86_64.whl',
'pymssql-2.2.1-cp39-cp39-manylinux1_i686.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux1_i686.whl',
'pymssql-2.2.1-cp36-cp36m-manylinux2014_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux_2_24_i686.whl',
'pymssql-2.2.1-cp37-cp37m-manylinux_2_24_x86_64.whl',
'pymssql-2.2.1-cp37-cp37m-win_amd64.whl',
'pymssql-2.2.1-cp38-cp38-manylinux2010_i686.whl',
'pymssql-2.2.1-cp38-cp38-manylinux1_x86_64.whl',
'pymssql-2.2.1-cp39-cp39-macosx_10_14_x86_64.whl',
'pymssql-2.2.1-cp39-cp39-manylinux2010_x86_64.whl',
]
>>> compatible_wheels(wheel_filenames)
['pymssql-2.2.1-cp39-cp39-manylinux_2_24_x86_64.whl', 'pymssql-2.2.1-cp39-cp39-manylinux2014_x86_64.whl', 'pymssql-2.2.1-cp39-cp39-manylinux1_x86_64.whl', 'pymssql-2.2.1-cp39-cp39-manylinux2010_x86_64.whl']
# Note: I get the above output because I am using Linux. You may be getting the wheels for windows accordingly based on your system.

Building VRPN server with Python 3.4 64-bit on Windows

I'm trying to build a VRPN server with Python3 flag using Python 3.4 64-bit on Windows 7 64-bit but there seems to be a problem. I need this for BlenderVR software.
This is my procedure:
1) I use CMake to create makefiles (I'm using 3.4.0 version but I've also tried different ones). I do it with this command (those flags should be there but the result seems to be the same without them anyway):
cmake -G"MinGW Makefiles" -HD:\My\BlenderVR\plugins\vrpn
-BD:\My\BlenderVR\plugins\cmake -DVRPN_BUILD_PYTHON=OFF -DVRPN_BUILD_PYTHON_HANDCODED_2X=OFF -DVRPN_BUILD_PYTHON_HANDCODED_3X=ON
I used to add those flags as well but it seems that it can find Python without them
-DPYTHON_INCLUDE_DIR=D:\My\BlenderVR\Required\Python3\include
-DPYTHON_LIBRARY=D:\My\BlenderVR\Required\Python3\libs\python34.lib
Python is correctly found and this operation doesn't throw any error.
2) Then I use mingw32-make.exe to build it and I get this error:
[ 90%] Linking CXX shared module vrpn.pyd D:/My/BlenderVR/Required/Python3/libs/python34.lib: error adding
symbols: File f ormat not recognized collect2.exe: error: ld
returned 1 exit status
python\CMakeFiles\vrpn-python.dir\build.make:505: recipe for
target 'python/vrpn .pyd' failed mingw32-make[2]: * * *
[python/vrpn.pyd] Error 1 CMakeFiles\Makefile2:3247: recipe for
target 'python/CMakeFiles/vrpn-python.dir/ all' failed
mingw32-make[1]: * * * [python/CMakeFiles/vrpn-python.dir/all]
Error 2 Makefile:159: recipe for target 'all' failed
mingw32-make: [all] Error 2
vprn.pyd is the crucial thing for my future work.
I figured out that it needs libpython34.a file (probably). When I created it and copied to Python3/libs folder it worked and finished without errors but the crated vprn.pyd didn't worked as it should.
What I need is to get import vrpn to work with this simple test in python (appending path where vrpn.pyd was build):
import sys
sys.path.append('D:/My/BlenderVR/plugins/cmake/python')
import vrpn
It lags my whole computer for a while and then pops out that Python has stop working.
I suspect that problem is in the libpython34.a file that I created doing this:
gendef python34.dll (in Windows/System32)
dlltool -D python34.dll -d python34.def -l libpython34.a
I don't how else should I get the libpython file. I've tried various versions of CMake and MinGW (like MinGWPy, TDM, w64) with many CMake flags. I was able to make it work using 32-bit Python but I need 64-bit version otherwise it is not working with BlenderVR enviroment.
I know this is very specific problem and probably kind of confusing at first but I didn't know how else to put it. I'll be glad for anything that could help. Thank you.
mingwpy should be installed with pip (until it is officially released at PYPI):
pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy
all necessary import files are atomatically copied into the python\libs folder.
If python\Scripts is in the PATH it should work out of the box.
You have to make sure, that Blender Python is equiped with two import files
D:\My\BlenderVR\Required\Python3\libs\libpython\libpython34.dll.a
D:\My\BlenderVR\Required\Python3\libs\libpython\libmsvcr100.a

Categories