1.1.1 1python多版本管理工具pyenv安装
1.作用
管理python解释器、python版本、python的虚拟环境
软件下载地址:https://github.com/pyenv/pyenv
2.pyenv软件包安装
a、配置yum源(配置文件内容如下)
vi CentOS6-Base-163.repo
[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
enable=1
gpgcheck=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
gpgcheck=0
enable=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
gpgcheck=0
enable=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
gpgcheck=0
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
gpgcheck=0
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
b、安装git软件和依赖包
yum install git -y
yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline- devel zlib-devel bzip2-devel
c、创建用户
useradd python
passwd python
d、安装pyenv软件
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
e、配置环境变量
vim ~/.bash_profile
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
1.1.2 3.使用pyenv软件安装和管理python
a、列出所有可用版本
pyenv versions
b、安装指定python版本
pyenv install --list
pyenv install 3.5.3 –v
/home/python/.pyenv
/home/python/.pyenv/cache---需手工建立
c、创建一个目录让local捆绑在一个目录下
pyenv versions------利用pyenv工具查看当前已安装python版本
* system (set by /home/python/.pyenv/version)
3.5.3
3.6.1
3.6.3
mkdir -p magedu/projects
cd magedu/projects/
pyenv local 3.5.3----------------#让python版本捆绑在一个目录下
python -V
Python 3.5.3
cd-------#你看如果在其它目录,python版本就是系统默认的2.6,local登录基本做到隔离
python -V
Python 2.6.6
pyenv virtualenv用法
pyenv virtualenv 3.6.3 mage363
pyenv versions
system
3.5.3
3.6.1
* 3.6.3 (set by /home/python/magedu/projects/web/.python-version)
3.6.3/envs/mage363
* mage363 (set by /home/python/magedu/projects/web/.python-version)
pyenv local mage363
(mage363) [python@python web]$
1.2 开发工具IPython Notebook的安装
1.2.1 1、配置pip国内源
mkdir /root/.pip
vim /root/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
pip -V
pip 9.0.1 from /home/python/.pyenv/versions/3.5.3/lib/python3.5/site-packages (python 3.5)
1.2.2 2 、安装jupyter
pip install IPython
pip install urllib3 –安装IPython Notebook的依赖
pip install jupyter –安装IPython Notebook
1.2.3 3、启动和修改密码
jupyter notebook --ip=0.0.0.0 --port 8000 --allow-root --no-browser
http://192.168.12.128:8080/
jupyter notebook --generate-config-----生成配置文件
生产密码和修改配置文件
Preparing a hashed password
Ipython
You can prepare a hashed password manually, using the function notebook.auth.security.passwd():
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
vi jupyter_notebook_config.py(添加密码行)
c.NotebookApp.password = u'sha1:a025bae1e107:247f2a22dbd90d2bbeb0aa4e4af6cb3268dcee8f'
重启验证
jupyter notebook --ip=0.0.0.0 --port 8000 --allow-root --no-browser
1.3 3利用pip工具快速在不同项目导入导出包
1.3.1 1、接下来在这个环境,把安装的所有包导出:
(magedu353) [python@python9 cmdb]$ pip freeze >/tmp/packs.txt
(magedu353) [python@python9 cmdb]$ cat /tmp/packs.txt
1.3.2 2、#我们去web环境目录
pip install -r /tmp/packs.txt
#这样就相当于在部署跟cmdb上的环境包了(导入包)
1.4 4win开发工具PyCharm安装
1、 jupyter安装
安装
pip install jupyter
启动
jupyter notebook