如何正確使用Anaconda配置Python搏恤,R環(huán)境

這篇文章摘于我寫在github上的一篇文章,希望大家多提意見舶赔,謝謝扫倡。

How to set up your own anaconda in a scientific way?

python2, python3, R in conda

Introduction

  • what is anaconda?

    • According to its own website, Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python and R and includes over 100 of the most popular Python, R and Scala packages for data science.
    • Or you can simply regard it as a manager of the packages of your programming languages.
  • why we want to use anaconda?

    • Convinient to manage packages
    • Jupyter notebook
  • object

    • Set up anaconda for a python and r user (linux)
    • I use py2 more often so I set it my default environment

Get started!

  1. Click this link and download corresponding version of anaconda.

  2. Type the following line in the terminal and the installation will be set up automatically

     ```bash Anaconda2-4.3.1-Linux-x86_64.sh``` . 
    

Do include the "bash" command even if you are not using the bash shell.

  1. Add the following line to the .bashrc or .zshrc(if you are a zsh user).

     ```export PATH="/home/zijun/anaconda2/bin:$PATH"```
    
  2. Create python3 environment in your conda.

     ```conda create -n py3 python=3.5 anaconda```
    
  3. Create R environment in your conda.

     ```conda create -n r -c r r-essentials```
    
  4. Install tck for R (enable install.packages() in R)

     ```source activate r
        conda install -c intel tcl=8.6.4```
    
  5. Note1: if you want to remove environment you install:

     ```conda remove --name py3 --all```
    
  6. Note2: switch different environment

     ```source activate r
        source deactivate r```
    

Some issues you may encounter during the process

Q: tcl not found

install.packages('highfrequency')
--- Please select a CRAN mirror for use in this session ---
Error: .onLoad failed in loadNamespace() for 'tcltk', details:
call: fun(libname, pkgname)
error: Can't find a usable init.tcl in the following directories:
/opt/anaconda1anaconda2anaconda3/lib/tcl8.5 ./lib/tcl8.5 ./lib/tcl8.5 ./library ./library ./tcl8.5.18/library ./tcl8.5.18/library

A: Solution:

  • Just do the step 5 above to solve this problem.

  • Or add the following lines to the .bashrc or .zshrc

     ``` export TCL_LIBRARY="/home/zijun/anaconda2/lib/tcl8.5"
         export TK_LIBRARY="/home/zijun/anaconda2/lib/tk8.5" ```
    
  • Note1: tck is a package which supports install.packages() function and it is installed in the global environment if you use sudo apt-get install tcl8.5-dev tk8.5-dev and conda has no access to it.

  • Note2: packages will be installed in /home/zijun/anaconda/envs/r/lib/R/library using install.packages()

Q: How to install packages in R

A: Since we set up the tcl, we can easily use install.packages() or remove.packages() to manage the R packages. However in this way, conda will lose control over r packages. Also you may find some suggestions using conda-build like this:

  • switch back to the root environment
  • type conda install conda-build in the terminal
  • Use conda skeleton cran and conda build to install packages (you may mind the dependency issue)

However this will not give you the control either. Moreover, there might be more issues about shitty sytax in R. So my suggestion is simply using install.packages() in R to install your packages.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市竟纳,隨后出現(xiàn)的幾起案子撵溃,更是在濱河造成了極大的恐慌,老刑警劉巖锥累,帶你破解...
    沈念sama閱讀 217,185評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缘挑,死亡現(xiàn)場離奇詭異,居然都是意外死亡桶略,警方通過查閱死者的電腦和手機(jī)语淘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,652評論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來际歼,“玉大人惶翻,你說我怎么就攤上這事《煨模” “怎么了吕粗?”我有些...
    開封第一講書人閱讀 163,524評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長旭愧。 經(jīng)常有香客問我颅筋,道長宙暇,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,339評論 1 293
  • 正文 為了忘掉前任垃沦,我火速辦了婚禮客给,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘肢簿。我一直安慰自己靶剑,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,387評論 6 391
  • 文/花漫 我一把揭開白布池充。 她就那樣靜靜地躺著桩引,像睡著了一般。 火紅的嫁衣襯著肌膚如雪收夸。 梳的紋絲不亂的頭發(fā)上坑匠,一...
    開封第一講書人閱讀 51,287評論 1 301
  • 那天,我揣著相機(jī)與錄音卧惜,去河邊找鬼厘灼。 笑死,一個胖子當(dāng)著我的面吹牛咽瓷,可吹牛的內(nèi)容都是我干的设凹。 我是一名探鬼主播,決...
    沈念sama閱讀 40,130評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼茅姜,長吁一口氣:“原來是場噩夢啊……” “哼闪朱!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起钻洒,我...
    開封第一講書人閱讀 38,985評論 0 275
  • 序言:老撾萬榮一對情侶失蹤奋姿,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后素标,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體称诗,經(jīng)...
    沈念sama閱讀 45,420評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,617評論 3 334
  • 正文 我和宋清朗相戀三年糯钙,在試婚紗的時候發(fā)現(xiàn)自己被綠了粪狼。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,779評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡任岸,死狀恐怖再榄,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情享潜,我是刑警寧澤困鸥,帶...
    沈念sama閱讀 35,477評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響疾就,放射性物質(zhì)發(fā)生泄漏澜术。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,088評論 3 328
  • 文/蒙蒙 一猬腰、第九天 我趴在偏房一處隱蔽的房頂上張望鸟废。 院中可真熱鬧,春花似錦姑荷、人聲如沸盒延。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,716評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽添寺。三九已至,卻和暖如春懈费,著一層夾襖步出監(jiān)牢的瞬間计露,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,857評論 1 269
  • 我被黑心中介騙來泰國打工憎乙, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留票罐,地道東北人。 一個月前我還...
    沈念sama閱讀 47,876評論 2 370
  • 正文 我出身青樓泞边,卻偏偏與公主長得像胶坠,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子繁堡,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,700評論 2 354

推薦閱讀更多精彩內(nèi)容