Skip to content

Instantly share code, notes, and snippets.

@xoyabc
Last active May 14, 2020 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoyabc/f1a8d4691fd50296a32bc9d414f67f5b to your computer and use it in GitHub Desktop.
Save xoyabc/f1a8d4691fd50296a32bc9d414f67f5b to your computer and use it in GitHub Desktop.

python环境搭建

环境准备

开课前环境准备
- 1. 如果你用的Windows系统,建议在Windows上安装虚拟机,在虚拟机上安装Linux系统,Linux系统上运行Python环境;
- 2. 如果你用的是Mac系统,那么可以直接在Mac上运行Python环境;
- 3. 虚拟机建议用Virtualbox + Vagrant, 为什么要用这款软件了??? 
- 3.1 能够实现Windows下项目代码实时同步到Linux系统;
- 3.2 Pycharm默认支持连接Virtualbox里的Python环境;

1. Windows系统

1.1 安装虚拟机

Virtualbox是一款虚拟机软件(类似于Vmware),Vagrant是Virtualbox的命令行管理工具, Box是虚拟机镜像;

1.1.1. 首先安装Virtualbox;

1.1.2. 安装Vagrant,如下图表示安装成功;

1.1.3. Vagrant命令行方式创建虚拟机;

1.1.3.1 Vagrant常用命令

1. vagrant box list  // 列出当前导入的Box
2. vagrant up        // 启动虚拟机
3. vagrant halt      // 关闭虚拟机
4. vagrant status    // 查看虚拟机的状态
5. vagrant init      // 初始化虚拟机
6. vagrant box add <BoxPath>  // 添加box
7. vboxmanage list vms   // 列出虚拟机
8. vagrant package --base vagrant_default_14950229427359_60979 --output soft/python36env_goenv_20180310.box  // 导出

1.1.3.2 进入Windows下的CMD命令行,使用Vagrant命令行工具来启动一台虚拟机。

替换自动生成的Vagrantfile配置文件

## 大概需要修改以下四处
config.vm.box = "centos-6.6-x86_64"    // 镜像的名称,但不包括扩展名。
config.vm.synced_folder "D:/51reboot-vm", "/home/vagrant/51reboot"  // 同步Windows下的文件夹到Linux上
config.vm.boot_timeout = 300           // 超时时间
config.vm.hostname = "51reboot"        // 设置主机名

Vagrant1 Vagrant2 Vagrant3 Vagrant4

1.1.3.3 使用xshell连接上Virtualbox虚拟机

登陆用户名 vagrant,登陆密码 vagrant,ssh端口 2222

Xshell Connect1 vm Xshell Connect2 vm Xshell Connect2 vm

1.2. Python 3.6

Linux安装

# yum install gcc gcc-c++ make openssl openssl-devel
# cd /usr/local/src
# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
# tar -zxvf Python-3.6.8.tgz
# cd Python-3.6.8
# ./configure --prefix=/usr/local/python36
# make -j
# make install

环境变量

# echo "export PATH=/usr/local/python36/bin:\$PATH" > /etc/profile.d/python36.sh
# source /etc/profile

测试版本

# python3 -V
Python 3.6.8

1.3. IDE

1.3.1 下载Pycharm 2019

1.3.2 安装Pycharm

Pycharm1 Pycharm1

1.3.3 Pycharm设置连接Vagrant虚拟机的Python环境,如下图;

Pycharm1 Pycharm1 Pycharm1 Pycharm1 Pycharm1 Pycharm1 Pycharm1 Pycharm1

2. Mac系统

2.1. Mac安装Python 3.6

测试版本

# python3 -V
Python 3.6.8

2.2. IDE

2.2.1 下载Pycharm 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment