我一直在努力保持我的環境非冗餘和清潔,因此我製作了一個R
環境,並在我的計算機上清除了所有其他現有的R
。在conda虛擬環境中,對`R`安裝的包使用`rpy2`?
這種環境稱爲r-conda
,它是:
/Users/jespinoz/anaconda/envs/r-conda/bin/R
,我意識到我沒有安裝rpy2
並通過暢達安裝它,它希望安裝的R
的新版本和所有我不想要的r-essentials
,因爲我已經有了一個完美的R環境。
我意識到我可以爲R conda
環境中相關的Python
安裝rpy2
:
source activate r-conda
pip install rpy2
source deactivate
但並不是所有的路徑都一字排開
我怎樣才能讓rpy2
承認我所有的R
的關聯的文件和路徑在我的r-conda
環境中?
它不能正確找到文件,當我試圖導入packges:加入這個我~/.bash_profile
os.environ['R_HOME'] = "/Users/jespinoz/anaconda/envs/r-conda/bin/R"
from rpy2.robjects.packages import importr
importr("dynamicTreeCut")
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-29-8b0a88dfe12d> in <module>()
1 # os.environ['R_HOME'] = '/Users/jespinoz/anaconda/envs/r-conda/bin/'
2 os.environ['R_HOME'] = "/Users/jespinoz/anaconda/envs/r-conda/bin/R"
----> 3 from rpy2.robjects.packages import importr
4 importr("dynamicTreeCut")
/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/robjects/__init__.py in <module>()
14 import itertools
15 from datetime import datetime
---> 16 import rpy2.rinterface as rinterface
17 import rpy2.rlike.container as rlc
18
/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/__init__.py in <module>()
90 del(os)
91
---> 92 from rpy2.rinterface._rinterface import (baseenv,
93 emptyenv,
94 endr,
ImportError: dlopen(/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so, 2): Library not loaded: @rpath/R/lib/libR.dylib
Referenced from: /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so
Reason: image not found
修正了一個錯誤,但產生一個類似的新的錯誤: 我這個做了嘗試,錯誤更改:
export LD_LIBRARY_PATH="/Users/jespinoz/anaconda/envs/r-conda/lib/R/lib/:$LD_LIBRARY_PATH"
>>> from rpy2.robjects.packages import importr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/robjects/__init__.py", line 16, in <module>
import rpy2.rinterface as rinterface
File "/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/__init__.py", line 92, in <module>
from rpy2.rinterface._rinterface import (baseenv,
ImportError: dlopen(/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so, 2): Library not loaded: libicuuc.54.dylib
Referenced from: /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so
Reason: image not found
所以,我想這一點,那麼得到了同樣的錯誤:
export LD_LIBRARY_PATH="/Users/jespinoz/anaconda/envs/r-conda/lib/R/lib/:/Users/jespinoz/anaconda/pkgs/icu-54.1-0/lib/:$LD_LIBRARY_PATH"
如果我使用conda install rpy2
即使我的主要conda環境的默認版本是Python=3.6
,它也想安裝Python=3.5.2
。
(r-conda) jespinozlt-osx:~ jespinoz$ conda install rpy2 python=3.6
Fetching package metadata .............
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- python 3.6*
- r-permute
- rpy2
Use "conda info <package>" to see the dependencies for each package
當我從我的'r-conda'環境安裝rpy2'時,即使該環境的默認'python'是我的主版本'python = 3.6',它也想安裝另一個版本的'python'。我唯一的選擇是安裝2個R版本,2個Python版本,還是將它們合併到同一個環境中?我覺得有些事情我可以用我的路徑和環境變量來告訴'rpy2'我的'R'文件所在的位置。 –
我不知道它爲什麼這樣做,但你可以通過將它包含在install命令中來強制它保留你想要的python版本,比如'conda install rpy2 python = 3.6'。 – asmeurer
我不知道你能做到這一點。很好,謝謝!雖然,它看起來像我得到了一些衝突的錯誤(更新問題B/C格式) ' –