linux安装python3

开发环境-Pyenv

python多版本管理工具

    管理python解释器

    管理python版本

    管理python的虚拟环境

pyenv安装
#yum -y install git

安装python编译依赖
#yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readine-devel zlib-devel bzip2-devel

创建python用户(也可以直接用root用户下载)
#useradd python
#su - python

安装pyenv,下载的pyenv-installer是一个shell脚本
$curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash


#!/usr/bin/env bash

set -e
[ -n "$PYENV_DEBUG" ] && set -x

if [ -z "$PYENV_ROOT" ]; then
  export PYENV_ROOT="${HOME}/.pyenv"
fi

colorize() {
  if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
  else echo -n "$2"
  fi
}

# Checks for `.pyenv` file, and suggests to remove it for installing
if [ -d "${PYENV_ROOT}" ]; then
  { echo
    colorize 1 "WARNING"
    echo ": Can not proceed with installation. Kindly remove the '${PYENV_ROOT}' directory first."
    echo
  } >&2
    exit 1
fi

failed_checkout() {
  echo "Failed to git clone $1"
  exit -1
}

checkout() {
  [ -d "$2" ] || git clone --depth 1 "$1" "$2" || failed_checkout "$1"
}

if ! command -v git 1>/dev/null 2>&1; then
  echo "pyenv: Git is not installed, can't continue." >&2
  exit 1
fi

if [ -n "${USE_GIT_URI}" ]; then
  GITHUB="git://github.com"
else
  GITHUB="https://github.com"
fi

checkout "${GITHUB}/pyenv/pyenv.git"            "${PYENV_ROOT}"
checkout "${GITHUB}/pyenv/pyenv-doctor.git"     "${PYENV_ROOT}/plugins/pyenv-doctor"
checkout "${GITHUB}/pyenv/pyenv-installer.git"  "${PYENV_ROOT}/plugins/pyenv-installer"
checkout "${GITHUB}/pyenv/pyenv-update.git"     "${PYENV_ROOT}/plugins/pyenv-update"
checkout "${GITHUB}/pyenv/pyenv-virtualenv.git" "${PYENV_ROOT}/plugins/pyenv-virtualenv"
checkout "${GITHUB}/pyenv/pyenv-which-ext.git"  "${PYENV_ROOT}/plugins/pyenv-which-ext"

if ! command -v pyenv 1>/dev/null; then
  { echo
    colorize 1 "WARNING"
    echo ": seems you still have not added 'pyenv' to the load path."
    echo
  } >&2

  { # Without args, `init` commands print installation help
    "${PYENV_ROOT}/bin/pyenv" init || true
    "${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
  } >&2
fi

在~/.bashrc的文件中添加

export PATH="/home/python/.pyenv/bin:$PATH"

eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

需要重新登录(加载文件)

 pyenvsh使用
$pyenv install -l

$pyenv install 3.5.3 -v

$python -V
显示当前版本

$pyenv version
查看当前版本
$pyenv versions
查看系统可以版本

Virtualenv虚拟环境

因为之前使用的python环境是公共的空间,如果多个项目使用不同python版本,会带来冲突,最好的解决办法就是每一个项目独立运行自己的独立小环境

(/home/python/.pyenv/versions/3.5.5/lib/python3.5/site-packages在大环境下,开发中所有的包都会放到这个目录中;

虚拟环境下安在这个目录/home/python/.pyenv/versions/3.5.5/envs/pikachu355/lib/python3.5/site-packages)

$pyenv virtualenv 3.5.3 pikachu353(起个新名字)
创建python3.5.3的独立运行的目录
$mkdir python

$cd python

$pyenv local pikachu353

pip通用配置

pip是python的包管理工具,3.x版本自带,和yum一样为了使用国内镜像配置如下

$mkdri ~/.pip
$vim ~/.pip/pip.conf

 [global]

index-url=Simple Index

trusted-host=mirrors.aliyun.com

$pip help install

$pip install ipython

pip升级
$pip install --upgrade pip

$pip install jupyter
安装可视化界面

$jupyter notebook --help
查看选项

$jupyter notebook password
设置密码

$jupyter notebook --ip=0.0.0.0
设置ip
导出包(在虚拟环境下)
$pip list
$pip freeze > requirement(名字自定义)
导入:
$pip install -r ../requirement

你可能感兴趣的:(python,python,linux,开发语言)