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)
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)
I'm trying update the latest opencv formula (as of writing, this formula installs opencv 2.4.7) to build the latest version of opencv (2.4.8).
The first thing I did was brew edit opencv, and change the url to 'https://github.com/Itseez/opencv/archive/2.4.8.tar.gz' and update the checksum. I anticipated that I might have to deal with some built issues, but the problem I see seems to occur while the formula is being run.
Specifically, when I run brew upgrade opencv (or unlink and run brew install opencv), I get the following message:
==> Downloading https://github.com/Itseez/opencv/archive/2.4.8.tar.gz
Already downloaded: /Library/Caches/Homebrew/opencv-2.4.8.tar.gz
==> Patching
patching file cmake/OpenCVFindOpenNI.cmake
Warning: Formula#python is deprecated and will go away shortly.
Error: undefined method `incdir' for #<PythonDependency: "python" []>
Please report this bug:
https://github.com/Homebrew/homebrew/wiki/troubleshooting
/usr/local/Library/Formula/opencv.rb:49:in `install'
/usr/local/Library/Homebrew/build.rb:165:in `install'
/usr/local/Library/Homebrew/formula.rb:272:in `brew'
/usr/local/Library/Homebrew/formula.rb:617:in `stage'
/usr/local/Library/Homebrew/resource.rb:63:in `unpack'
/usr/local/Library/Homebrew/extend/fileutils.rb:21:in `mktemp'
/usr/local/Library/Homebrew/resource.rb:60:in `unpack'
/usr/local/Library/Homebrew/resource.rb:53:in `stage'
/usr/local/Library/Homebrew/formula.rb:615:in `stage'
/usr/local/Library/Homebrew/formula.rb:267:in `brew'
/usr/local/Library/Homebrew/build.rb:144:in `install'
/usr/local/Library/Homebrew/build.rb:45:in `main'
/usr/local/Library/Homebrew/build.rb:12
/usr/local/Library/Formula/opencv.rb:80
Python doesn't seem to get loaded. I'm also confused by the deprecation warning; everything I've found suggests that python formula is the one I should be using. Judging by this link the depends_on :python dependency seems like it should work (and it obviously did when I tried with the previous 2.4.7.1 formula).
For reference, here are my environment variables:
Apple_PubSub_Socket_Render=/tmp/launch-Ygtqzn/Render
CMD_DURATION=20.7s
COMMAND_MODE=unix2003
DISPLAY=/tmp/launch-a4CGwS/org.x:0
GEM_HOME=/Users/myname/.rvm/gems/ruby-1.9.3-p194
GEM_PATH=/Users/myname/.rvm/gems/ruby-1.9.3-p194:/Users/myname/.rvm/gems/ruby-1.9.3-p194#global
GREP_COLOR=97;45
GREP_OPTIONS=--color=auto
HOME=/Users/myname
LANG=en_CA.UTF-8
LOGNAME=myname
PATH=/usr/local/bin:/Users/myname/.rvm/gems/ruby-1.9.3-p194/bin:/Users/myname/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/myname/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/myname/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin:/Users/myname/.rvm/bin:/usr/local/heroku/bin
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11/lib/pkgconfig
PWD=/Users/myname/projects/forks/ruby-opencv
SHELL=/usr/local/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/tmp/launch-lvn79S/Listeners
TERM=xterm-color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=273.1
TMPDIR=/var/folders/pv/pvvR8qgvGOCfd5dza+ZbVU+++TI/-Tmp-/
USER=myname
__CF_USER_TEXT_ENCODING=0x1F5:0:0
__fish_bin_dir=/usr/local/Cellar/fish/2.0.0/bin
__fish_datadir=/usr/local/Cellar/fish/2.0.0/share/fish
__fish_help_dir=/usr/local/Cellar/fish/2.0.0/share/doc/fish
__fish_sysconfdir=/usr/local/Cellar/fish/2.0.0/etc/fish
rvm_bin_path=/Users/myname/.rvm/bin
rvm_path=/Users/myname/.rvm
rvm_prefix=/Users/myname
rvm_version=1.25.3:master
And python (homebrewed) version
python --version #=>Python 2.7.6
brew doctor output gives me a warning about a passenger config file (which shouldn't influence the building of opencv) and a warning that opencv is unlinked (I unlinked it to try running brew install opencv)
Thanks in advance for the help.
I had the same error. I don't understand why "incdir" or other variables are not defined correctly in the formula file. But I solved this error by editing the opencv formula file as follows, (setting each path directly)
(around 50th lines)
DPYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/include/python2.7
DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
DPYTHON_EXECUTABLE=/usr/local/bin/python
I worked around this issue by rolling back to an earlier homebrew version, then installing opencv, and then going back to the current version.
See this gist for detailed instructions: https://gist.github.com/frederikhermans/8561382
I am getting this error when trying to run a classic python code written by x-colleagues.
Can u anyone help me out with solving this issue. I have googled throughly and couldn't find any solution.
Python version : 2.4.3
ImportError: /usr/lib/python2.4/lib-dynload/pyexpat.so: symbol XML_SetHashSalt, version EXPAT_1_95_8_RH not defined in file libexpat.so.0 with link time reference
I got the same problem and the root cause for me is that i built libexpat myself from source but pyexpat.so seems to depand on RH customized libexpat version.
So check your dependencies with:
ldd /usr/lib/python2.4/lib-dynload/pyexpat.so
Then check your libexpat.so file. If possible, you can try to re-install the rpm of expat-devel.x86_64 (for 64 bit).
yum install expat-devel.x86_64
We've installed mercurial 1.4.1 and python 2.6.2 on a solaris 8 box. Now some hg commands work as expected, others fail.
I was able to initialize a repository (hg init) and add a file (hg add) but the committing (hg commit) leads to an error message:
abort: could not import module found!
I need a hint where to look - I'm not a python expert, is this missing found module part of the python distribution or does it belong to mercurial? Any idea how to fix it?
Edit
Thanks for your comments - hg debuginstall runs fine, just reports one problem - I didn't set a username in any of the config files. Can't believe that this causes the actual problems...
Edit
--traceback was a good hint!!
Here's the last line (can't copy&paste):
ImportError: ld.so.1: hg: fatal: relocation error:
file:/usr/local/lib/python2.6/lib-dynload/zlib.so:
symbol inflateCopy: referenced symbol not found
The zlib.so library is present was installed with either the python or mercurial package.
Looks like I'm not the only one: here's the same problem with python 2.5 on solaris 10
You need to install the zlib library for your system (libz.so).
Check your LD_LIBRARY_PATH settings.
If it is pulling libz from an odd place you will need to fix it so that it is pulling from /pkg/local/lib first
I was seeing this:
ldd /pkg/local/lib/python2.7/lib-dynload/zlib.so
libz.so => /import/wgs/lib/libz.so
But now its working for me.