How to correctly install rpy2 in python? - python

There are a lot of other questions like mine but they're quite outdated so I think a new updated guide would be helpful for everyone trying to install rpy2 in Python.
In my case, I'm trying to work with the package pymer4 but i couldn't manage to correctly import it.
I found out that the error lies in rpy2.robjects so I decided to follow this answer to create a clean environment
Steps
I created a new conda environment
conda create -n rpy2_env r-essentials<4.2 r-base<4.2 python=3.7
I set the version to <4.2 because I read online this problem can be caused by a wrong r version. Anyway neither 4.2 nor 4.1 worked for me.
I installed the pymer4 package (and its dependecies, including rpy2)
conda install -c ejolly -c conda-forge pymer4
I downgraded rpy2 to 3.4.5 (see related question below, I also tried without downgrading)
conda install rpy2=3.4.5
When i try to import pymer4 or rpy2.robjects the following error shows up
R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) :
3 arguments passed to .Internal(gettext) which requires 2
In the terminal the logs showed no error during download and installation.
If you need more info about my system or anything else, comment and I will update the question.
I am really stuck at this point, I think i tried everything I could. I would really appreciate if someone could enlighten me.
Similar Questions
Import rpy2 : unable to determine R library path
Rpy2 can't find my R libraries on install
R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) : 3 arguments passed to .Internal(gettext) which requires 2

I think I found the solution.
The problem is with conda and rpy2, apparently rpy2 installed with conda is outdated.
You can install correctly rpy2 on a new environment (venv or conda env) using pip.
I did it and so far it's working perfectly.

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?

No module found error for a downloaded package (sksparse.cholmod) and how to download a package from the internet to conda

I need to use the sksparse.chomod package however my pycharm does not let me install it as it can't seem to find it.
I found the sksparse package on github and downloaded it but I do not know how to add a package downloaded from the internet into a conda environment. So, my first question would be can you download a package from github and add it to your conda environment, and how do you do this?
As I did not know how to do the above I instead saved the package within my project and thought I could simply import sksparse.cholmod. However, the line in my code that says import sksparse.cholmod as sks has no errors with it, so I assumed that meant this was ok, but when I try to run my file I get this error:
import sksparse.cholmod as sks
ModuleNotFoundError: No module named 'sksparse.cholmod'
If I have downloaded the package into my project why can't it be found, yet there are no errors when importing?
The cholmod file is a pyx file which I've been told should not be a problem.
Please could anyone help, I am reasonably new to python and I am looking for a straight forward solution that won't be time consuming.
It was an issue with windows, I was able to fix this using the instructions on this link
https://github.com/EmJay276/scikit-sparse
We must follow these steps precisely:
(This was tested with a Anaconda 3 installation and Python 3.7)
Install these requirements in order:
'''
conda install -c conda-forge numpy - tested with v1.19.1
conda install -c anaconda scipy - tested with v1.5.0
conda install -c conda-forge cython - tested with v0.29.21
conda install -c conda-forge suitesparse - tested with v5.4.0
'''
Download Microsoft Build Tools for C++ from https://visualstudio.microsoft.com/de/visual-cpp-build-tools/ (tested with 2019, should work with 2015 or newer)
Install Visual Studio Build Tools
Choose Workloads
Check "C++ Buildtools"
Keep standard settings
Run ''' pip install git+https://github.com/EmJay276/scikit-sparse '''
Test ''' from sksparse.cholmod import cholesky '''
Use all the versions stated for numpy etc, however with scipy I installed the latest version and it worked fine.

Installing biopython: can't match required version of mkl

I tried to install biopython on Linux Mint 19.3. I got an error message; package mkl==2020.0-166 was missing. I was able to downgrade to that version and tried again, but conda still claims the required version is missing. The list output shows: 'mkl [version] 2020.0 [build] 166'. I don't seem to understand how to give biopython the specific version it needs.
I found the question, How do I install biopython in anaconda?
which is closely related. I tried installing from the conda-forge cahnnel without success. Navigator also gave me the same error.
Here is the information about my system and the results I got:
** information pulled because I couldn't format it right.**

Need help installing fiona and geopandas for python in Windows 10 - getting can't load requested DLL error

I am trying to install fiona and geopandas for python on Windows 10 and keep running into an error "ERROR 1: Can't load requested DLL".
I know this question is similar to other questions that have been asked, but I have followed the steps in multiple answers and tutorials and still can't seem to get this to work.
The closest I got was using the steps outlined in this tutorial : https://geoffboeing.com/2014/09/using-geopandas-windows/
and are summarized as follows:
installed the .whl files for rtree, pyproj, shapely, gdal, geopandas, fiona from https://www.lfd.uci.edu/~gohlke/pythonlibs/
Rtree-0.8.3-cp37-cp37m-win_amd64.whl
pyproj-2.2.1-cp37-cp37m-win_amd64.whl
GDAL-3.0.0-cp37-cp37m-win_amd64.whl
geopandas-0.5.0-py2.py3-none-any.whl
Fiona-1.8.6-cp37-cp37m-win_amd64.whl
Shapely-1.6.4.post2-cp37-cp37m-win_amd64.whl
navigated to download folder and used pip install to install GDAL wheel
added the osgeo path to my windows user Path environment variable
used pip install to install remaining wheels (geopandas last), everything installed without errors
As a check, I ran gdalinfo --help-general and get the following output:
This is where I get the "ERROR 1: Can't load requested DLL:" error. It says it cannot find the specified module "ogr_FileGDB.dll". The weird thing is, that .dll is actually in the location that it is looking in???
Also, in python shell, when trying to import fiona or geopandas I get the following errors:
This is beyond my level of troubleshooting...would really appreciate if anyone could get this thing working for me!!!!
FYI - running Python 3.7.3, Windows 10, pip is updated.
Lastly and potentially important (not sure how it plays in?) I already have a GDAL_DATA system variable defined, and also (maybe incorrectly?) also tried adding the osgeo path to my system path variable:
I was using a GDAL version that was not compatible with Fiona and subsequently causing issues with geopandas.
I uninstalled GDAL 3 and installed GDAL 2.4.1 and it worked fine, as cgohlke suggested.
Install fiona with conda, then that will solve the GDAL problem. pip install geopandas should work after that.

BLAS environment variable

Using Microsoft Windows 7.0 OS and wanted to be able to call pip for ease of installing Python modules. I first installed distribute.
After running the module:
pip install -U scikit-learn
I realized that I need to set the BLAS environment variable. I do not fully understand what this entails, i.e. what should it be set to? set BLAS="something"
(Note: I also skipped this and tried: easy_install -U scikit-learn, which seemed to work fine. But when I attempt to import the module in iPython it doesn't recognize it, it gives "invalid syntax" pointing to "-").
Appreciate your thoughts.

Categories