解決:在anaconda下無法使用conda安裝第三方庫問題

Anaconda2
Python 2.7.12
雲服務器:ESC Ubuntu 16.04 x64


問題

無法使用conda進行安裝第三方包

mrlevo@mrlevo-Lenovo:~$ conda install folium
Fetching package metadata …
CondaHTTPError: HTTP None None for url https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/repodata.json
Elapsed: None
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError(‘HTTPSConnectionPool(host=\’mirrors.tuna.tsinghua.edu.cn\’, port=443): Max retries exceeded with url: /anaconda/pkgs/free/ladTimeoutError(“HTTPSConnectionPool(host=\’mirrors.tuna.tsinghua.edu.cn\’, port=443): Read timed out. (read timeout=9.15)”,))’,),)


解決方案1

修改其包管理鏡像爲國內源, 簡單來說,就是在終端運行這兩句話

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

然後再試試,如果不行,我想了個終極解決方案,啊哈哈


解決方案2

當然首先保證你的pip可用,如果pip都不行,你該檢查下網絡了。。正題,簡單說,就是pip安裝包之後,把包拷貝到anaconda的包路徑下,哈哈哈,因爲包根本沒有編譯的過程(對於不需要編譯的包)

# 步驟一:找到包依賴的所有包
$ pip install folium  # 前提是我已經裝了一次了
Requirement already satisfied: folium in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: Jinja2 in /usr/local/lib/python2.7/dist-packages (from folium)
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from folium)
Requirement already satisfied: branca in /usr/local/lib/python2.7/dist-packages (from folium)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2->folium)

# 從這裏可以看出folium依賴什麼包,路徑都在哪


# 步驟二,找到anaconda包的安裝路徑

mrlevo@mrlevo-Lenovo:~$ python
Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import pandas
pandas.__file__
>>> pandas.__file__
'/home/mrlevo/anaconda2/lib/python2.7/site-packages/pandas/__init__.pyc'

# 可以看出,包都在/home/mrlevo/anaconda2/lib/python2.7/site-packages/ 路徑下,哈哈哈,開始第三步

# 步驟三,複製pip的包到anaconda包的路徑下
mrlevo@mrlevo-Lenovo:~$ cp -r /usr/local/lib/python2.7/dist-packages/folium /home/mrlevo/anaconda2/lib/python2.7/site-packages/folium

# 注意這一步需要把所有與folium依賴的包都複製進來,當然anaconda有的不用複製
之後再進入python環境,import folium看看是不是可行了,哈哈哈

致謝

@小段同學的雜記–最省心的Python版本和第三方庫管理——初探Anaconda
@機智的自己

發佈了97 篇原創文章 · 獲贊 424 · 訪問量 92萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章