红联Linux门户
Linux帮助

解决:在anaconda下无法使用conda安装第三方库问题

发布时间:2017-06-15 09:37:39来源:linux网站作者:哈士奇说喵
系统环境
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看看是不是可行了。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31487.html