栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python数据挖掘 环境搭建

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python数据挖掘 环境搭建

deepin

有很多小伙伴想学习python,但windows写python基本是坑,deepin属于linux分支,界面美观,内置大量桌面软件,对新手十分友好,这里尝试在深度系统(deepin)内安装python开发工具 jupyter,并完成一个绘制折线图的入门案例

将默认的bash更换为zsh(个人喜好,可跳过)
  • 首先,安装zsh:

sudo apt-get install zsh
  • 先安装git

sudo apt-get install git
  • 再安装oh-my-zsh

sudo wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
  • 切换到 zsh 模式

chsh -s /usr/local/bin/zsh
  • 配置.zshrc(可跳过)

cd ~
git clone git://github.com/seebi/zshrc.git .zsh
cd .zsh/
make install
安装python2, python3
sudo apt install python2
sudo apt install python3
安装pip
sudo apt install python-pip
安装pip3
sudo apt install python3-pip
apt安装virtualenv
sudo apt install virtualenv
pip安装virtualenv
pip install virtualenv
pip安装virtualenvwrapper
pip install virtualenvwrapper
配置virtualenvwrapper
  • 默认查看virualenvwrapper.sh的位置为

$HOME/.local/bin/virtualenvwrapper.sh
  • 在.zshrc底部新增

export WORKON_HOME=$HOME/.virtualenvssource $HOME/.local/bin/virtualenvwrapper.sh

新增virtualenvwrapper配置项

  • 在shell中执行

source $HOME/.zshrc
创建python2和python3虚拟开发环境
  • 查看python2解释器所在位置(这里得到的路径为/usr/bin/python2.7)

whereis python2
  • 创建python2开发环境

mkvirtualenv py2 -p /usr/bin/python2.7
  • 查看python3解释器所在位置(这里得到的路径为/usr/bin/python3.5)

whereis python3
  • 创建python3开发环境

mkvirtualenv py3 -p /usr/bin/python3.5
virtualenvwrapper的使用
  • 进入到python2环境

workon py2
  • 从python2切换到python3环境(切换和进入是同一个命令)

workon py3
  • 虚拟环境中安装软件(以jupyter为例)

# 安装jupyterpip3 install jupyter
  • virtualenvwrapper命令扩展(新手安装环境,请直接跳过)

#导出 虚拟环境中的包(备份)pip freeze > requirements.txt# 导入 安装备份的包信息(恢复)pip install -r requirements.txt# 退出虚拟环境deactivate# 删除虚拟环境rmvirtualenv 环境名
jupyter启动
# 进入刚刚安装jupyter的虚拟环境workon py3# 开启jupyterjupyter notebook

启动jupyter

在py3下新建工作空间

jupyter跑起来

在jupyter中安装 matplotlib 进行绘图(绘制折线图,并保存)
pip install matplotlib
import matplotlib.pyplot as pltimport randomimport matplotlib.pyplot as plt# 保证生成的图片在浏览器内显示%matplotlib inline
plt.rcParams['font.family'] = ['Arial Unicode MS', 'sans-serif']# 指定画板的大小等等plt.figure(figsize=(6, 6), dpi=100)# 指定axis的一些坐标点,必须是列表x = [1,2,3,4,5,6,7]
y = [107,17,108,15,101,11,102]# 画出折线图plt.plot(x, y)# 将图片保存在文件同级目录下(必须在show()的前面调用)plt.savefig("./test.png")# 最终显示图plt.show()

代码分开执行

执行效果





转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/223688.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号