Reticulate can't install python packages - python

I'm trying to run the Seurat pipeline in RStudio (Windows 10 , which requires having the python library 'umap-learn' installed (Seurat walkthrough: https://satijalab.org/seurat/v3.0/pbmc3k_tutorial.html).
To install said library, I'm using the reticulate library in R in the following manner:
library(reticulate)
py_install(packages = 'umap-learn')
I'm getting the following error:
Error in conda_python(envname = envname, conda = conda) :
conda environment r-reticulate not found
I've tried just about everything I can think of:
Providing py_install with a path to python directly
Uninstall / Reinstall of RStudio
Uninstall / Reinstall of Anaconda
Tried adding Anaconda to system path
Using devtools version of Reticulate
Using the use_python function: use_python("C://Users/lvlah/Anaconda3/python.exe")
At my wit's end with this - none of my colleagues have had this issue. Any help would be appreciated.

I had the same problem and what seems to be an issue is that you need to first manually create the r-reticulate environment. I did it manually in Anaconda Navigator, but you can also do conda_create("r-reticulate") within R, as detailed in this tutorial.

I had exactly the same issue and after finding this helpful post I've solved it by installing OpenSSL. Hope it works for you!

Related

mac mecab dlopen: symbol not found in flat namespace error

I want to import MeCab and use it, but that error comes out repeatedly.
MeCab-python is well installed.
I've tried Brew install and so on, and it's still the same.
I'd appreciate it if you could help me if you knew the solution.
Hmm. On a fresh macOS 13.1 Ventura, I just did this:
Installed miniconda https://docs.conda.io/en/latest/miniconda.html#latest-miniconda-installer-links
conda create -n mecab-tutorial and answering questions
conda activate mecab-tutorial
conda install python ipython and saying 'yes'
python -m pip install mecab-python3 unidic-lite
Then I was able to run this script:
import MeCab
wakati = MeCab.Tagger("-Owakati")
wakati.parse("pythonが大好きです").split()
# ['python', 'が', '大好き', 'です']
Looking at the path in the error in the screenshot, it looks like you installed a global Python in /Library which I don't want to try because I very much prefer to keep my Python environments local, hence using Conda above to create a custom environment to install MeCab packages in to ensure no cross-contamination later.
There's no guarantee that this will work if you try it since the error you're seeing seems to be a compiler issue (Python is finding MeCab, just having trouble calling a C++ function inside the binary), but if possible, can you try the Conda approach above?

Can't find Brew installed packages on Mac M1 in Pycharm

I'm having trouble installing packages and using them in Pycharm. I've followed various threads (I'm new to Macs and seem to have tried everything) now I'm stuck.
In this case, I want to use the package xgboost.
I have brew installed, after launching a terminal using Rosetta:
%brew install xgboost
Warning: xgboost 1.3.3 is already installed and up-to-date.
It appears installed OK here:
/opt/homebrew/Cellar/xgboost
I also have Python installed here:
/opt/homebrew/Cellar/python#3.9
But no matter how I configure an Interpreter in Pycharm, I can't seem to get the package recognised.
Where have I gone wrong?
I am very unsure exactly how, but I've got this working.
Following: https://abbasegbeyemi.me/blog/homebrew-python-apple-m1
I changed the order of elements in my path:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin
then a new interpreter in Pycharm using:
usr/local/Cellar/Python#3.9/3.9.2_2/bin/python3.9
Now I can install packages just using pip in pycharm and it works.
This has been 6 hours of pain - warning to anyone who isn't well versed in macs, setting up an M1 for python dev was a complete nightmare for me.
Docs: https://xgboost.readthedocs.io/en/latest/build.html
Pre-built binary wheel for Python
If you are planning to use Python, consider installing XGBoost from a pre-built binary wheel, available from Python Package Index (PyPI). You may download and install it by running
# Ensure that you are downloading one of the following:
# * xgboost-{version}-py2.py3-none-manylinux1_x86_64.whl
# * xgboost-{version}-py2.py3-none-win_amd64.whl
pip3 install xgboost

Python from RMarkdown - Matplotlib problems

I'm trying to use reticulate to run some simple Python code in an RMarkdown document. I've found that if Matplotlib is in the conda environment, I get errors when trying to run a python code chunk, but I can run Python from R directly. Here's a simple example of what I see:
---
title: "Reticulate Test"
date: "9/21/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
use_condaenv('Toy_MPL') # this environment contain matplotlib and produces the error
#use_condaenv('Toy') # this environment does not contain matplotlib and no error
```
```{r}
# this works regardless of which environment I use
pysys <- import('sys')
pysys$version
```
[1] "3.8.5 (default, Sep 4 2020, 02:23:17) \n[Clang 10.0.0 ]"
```{python, engine.path = '/opt/miniconda2/envs/Toy_MPL/bin/python'}
# if Toy_MPL conda environment is used, the error is generated
# if Toy conda environment is used, I get the same output as above
import sys
print(sys.version)
```
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: use() got an unexpected keyword argument 'warn'
My first thought was that reticulate was not seeing the various system libraries that are installed in the conda environment lib/ folder when Matplotlib is installed - there are a LOT of dependencies that come along with Matplotlib. I tried the following, but none worked:
Set LD_LIBRARY_PATH in .Renviron to point to the correct library path.
Call use_python() in addition to or instead of use_condaenv()
set engine.path in the Python code chunk
I tried downgrading matplotlib to v3.2 (suggested here), but that caused a new set of errors:
Error in if (has_compatible_arch && has_preferred_numpy) valid_python_versions <- c(valid_python_versions, : missing value where TRUE/FALSE needed
Checking NumPy, I see I have v1.19.1 (other errors suggest needing >1.6). And, reinstalling matplotlib v3.3.1 does not prevent the error. After this "fix" I end up having to rebuild the entire environment.
traceback() gives me a CPP stack trace from the reticulate.so which is not interpretable.
My interpretation is that the environment created for RMarkdown does not point to the correct library locations, but I cannot determine how to set it correctly.
System info:
Mac OS Catalina 10.15.6
RStudio v1.3.1073
reticulate v1.16
conda v4.8.4
Python in conda environments v3.8.5
Matplotlib in Toy_MPL environment v3.3.1
In my original question, I referred to this question in which there was a suggestion to downgrade matplotlib to version 3.2.0 because reticulate was not up to date with changes in matplotlib. I followed up further on that suggestion and have found a resolution (for now).
TL;DR
Removing pip and conda installed versions of matplotlib, and then installation of matplotlib version 3.2.2 with conda (NOT pip) resolves the problem. Installing matplotlib with pip leads to other errors.
Details
In the response to the other question, the suggestion was to do:
pip install matplotlib==3.2
I tried this and ended up with other errors that I also could not track down. So, I uninstalled matplotlib and then reinstalled it with
pip install matplotlib==3.3.1
in hopes of getting back to where I was. This also did not work and the new errors persisted. I then removed matplotlib completely and with pip and reinstalled version 3.3.1 with conda:
pip uninstall matplolib
conda install matplotlib
This got me back to matplotlib version 3.3.1 and the original error I mention in my question. I then tried installing matplotlib version 3.2 with conda:
conda install matplotplib==3.2
The installed version is 3.2.2 and not 3.2.0, as suggested in the response, but when I did this, the original problem seems to be resolved.
There is clearly a difference in dependency resolution between pip and conda in this case, and conda provides a version of matplotlib that plays nicely with reticulate. I do not at this point know what the difference is, however.
I ran into a similar issue as well. I'm new to python so I used the Anaconda Navigator to manage my python environments and packages. I fixed my problem by doing the following.
Remove the reticulate package from R
Open the Anaconda Navigator and remove the r-reticulate environment from environments page. I also removed an additional conda environment that I had created with reticulate.
Re install the reticulate package and run your code
This won't help too much if you still want to use matplotlib with reticulate, but it should at least get your script running again if it doesn't use matplotlib.

(Alternative solution) Issues with Anaconda install - Failed to create Anaconda menus

I recently uninstalled Anaconda 3 as it was giving me issues but after installing it and trying to use the latest Anaconda3-2019.10 for Windows I got the "Failed to create Anaconda menus" error each time i installed. I check PATHs, checked and cleaned registry and still not hope.
SOLUTION: Some how re-installing the exact same old version of Anaconda3-5.2.0-Windows-x86_64 worked!
I cannot explain it.

conda skeleton cran uses wrong version of R

I am trying to package some R packages from CRAN to use in a conda environment because I am using a combination of Python and R packages for a bioinformatics pipeline. Because of other dependencies, I need to keep R at version 3.3
I made a brandnew environment with the version of Python and R I want:
$ conda create -n bioinfo python=3.6.3 r=3.3.2
There is no R installed in the root environment. Then I follow the instructions for conda skeleton:
(bioinfo)$ conda skeleton cran rootSolve
(bioinfo)$ conda skeleton cran rootSolve
(bioinfo)$ conda build r-rootsolve
For some reason, this keeps coming up with an R3.4 dependency, even though according to CRAN, the rootSolve package only needs R>=2.01! Where is this coming from??
The following NEW packages will be INSTALLED:
r-base: 3.4.2-haf99962_0
Though building the package does not actually change the version of R running in my environment, the package does not load. Any ideas, please?
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
> library('rootSolve')
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/people/bioc1402/miniconda3/envs/bioinfo2/lib/R/library/rootSolve/libs/rootSolve.so':
/usr/people/bioc1402/miniconda3/envs/bioinfo2/lib/R/library/rootSolve/libs/rootSolve.so: undefined symbol: R_ExternalPtrAddrFn
In addition: Warning message:
package ‘rootSolve’ was built under R version 3.4.2
Error: package or namespace load failed for ‘rootSolve’
Apparently this was a bug, now fixed in conda-build 3.1.3,
https://github.com/conda/conda-build/issues/2562
Thanks conda team!
'conda build r-rootsolve --R=3.3.1' now works appropriately with the recipe generated by conda skeleton.

Categories