layout: post # 使用的布局(不需要改)title: AllenNLP安装 # 标题
subtitle: Linux安装python3.6 & AllenNLP库 #副标题
date: 2018-11-05 # 时间
author: NSX # 作者
header-img: img/post-bg-2015.jpg #这篇文章标题背景图片
catalog: true # 是否归档
tags: #标签
- 教程

Linux安装python3.6

AllenNLP requires Python 3.6.1 or later. and CUDA 9 only (or no GPU)
https://www.cnblogs.com/kimyeee/p/7250560.html

  1. 安装依赖环境

# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

  1. 下载Python3

https://www.python.org/downloads/

# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

3.安装python3

我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)

创建目录:

# mkdir -p /usr/local/python3

进入python3目录,解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同⽽而不不同,如:我下载的是Python3.6.5.那我这里就是Python-3.6.5.tgz)

# tar -zxvf Python-3.6.5.tgz

4.进入解压后的目录,编译安装。

在安装python时 ./configure指定引入ssl, 否则使用pip36 install xxx命令时报ssl缺失的错误
https://blog.csdn.net/youcijibi/article/details/78306961
https://blog.csdn.net/ChangerJJLee/article/details/83112006

  1. # cd Python-3.6.5
  2. # ./configure --with-ssl --prefix=/usr/local/python3
  3. # make && make install

5.建立python3的软链

# ln -s /usr/local/python3/bin/python3 /usr/bin/python36

6.并将/usr/local/python3/bin加入PATH

  1. # vim ~/.bash_profile
  2. # .bash_profile
  3. # Get the aliases and functions
  4. if [ -f ~/.bashrc ]; then
  5. . ~/.bashrc
  6. fi
  7. # User specific environment and startup programs
  8. PATH=$PATH:$HOME/bin:/usr/local/python3/bin
  9. export PATH
  10. ESC,输入:wq回车退出。

修改完记得执行行下面的命令,让上一步的修改生效:

# source ~/.bash_profile

检查Python3及pip3是否正常可用:

  1. # python36 -V
  2. Python 3.6.5
  3. # pip36 -V
  4. pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

7.不行的话在创建一下pip3的软链接

# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip36

安装allennlp包

https://github.com/allenai/allennlp

  1. Installing the library and dependencies is simple using pip.

# pip36 install allennlp

  1. You can now test your installation with allennlp test-install .