python-2/02-Python开发环境.md
2024-12-26 09:59:08 +08:00

225 lines
5.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 02-Python开发环境
python golang
java php ruby
c c++
python php bash 脚本语言 解释型语言
## 一、Python安装
现在Centos8已经取消Python2.7,默认自带Python3.6和Python3.8
windows环境安装了python3.9
打开python3.9的解释器
## 二、pip用法
Centos8里面必须使用pip3命令直接使用pip不可用
pip是Python 包管理器
管理的是python第三方包
Python 的库
1.标准库
目录/usr/lib64/python3.6 内除了site-packages其他的库都是内置标准库
2.第三方库
存放目录: /usr/lib64/python3.6/site-packages
第三方库由pip管理
```bash
# pip3 install 包名字
# pip3 install requests
# pip3 install pillow
# pip3 install flask
# pip3 install django==版本号
# pip3 uninstall 包名字
# pip3 list 查看安装的第三方包
```
跨平台移动python环境的时候使用freeze收集已经安装好的模块安装到其他系统内
```bash
# pip3 freeze > requirements.txt 将第三方的包输出到一个文件中,文件名:requirements.txt
# pip3 install -r requirements.txt 将requirements.txt文件中的所有的第三方包一次性安装
```
下载 pypi.org
解压
cd
python setup.py install
php扩展包 pecl.php.net
php mysql redis
## 三、使用ipython
```bash
python2.7
# yum install -y epel-release
# yum search pip
# yum install python-ipython
python3
# yum install python3
# yum install python3-pip
# pip3 install ipython
```
```bash
# pip3 install ipython
```
2版本的ipython自带tab补全但是3版本取消掉了解决方法如下
```bash
# pip3 install jedi==0.17.2
```
## 四、IDE集成开发环境
常用Python IDE环境
pycharm
vscode
**vscode基本使用**
### 1、下载安装
官方网站下载,按官方提示安装即可
![image-20200916114956638](assets/image-20200916114956638.png)
![image-20200916115044429](assets/image-20200916115044429.png)
### 2、安装插件
打开商店,安装中文简体插件
![image-20200916115306793](assets/image-20200916115306793.png)
安装文档图标
![image-20200916115345855](assets/image-20200916115345855.png)
### 3、基本设置
![image-20200916115449910](assets/image-20200916115449910.png)
打开配置文件方式
![image-20200916115526379](assets/image-20200916115526379.png)
添加如下内容到 `settings.json` 配置文件中,并按下 `Control + s` 保存**
```json
{
"editor.fontSize": 30,
"debug.console.fontSize": 30,
"markdown.preview.fontSize": 26,
"terminal.integrated.fontSize": 30,
// 编辑的文件 每 1 秒自动保存一次
"files.autoSave": "afterDelay"
}
```
在打开文件夹创建python文件的时候会提示安装python扩展跟随提示安装即可
![image-20200916120135841](assets/image-20200916120135841.png)
### 4、配置默认 python 解释器
> vscode 默认选择的python 解释器是 python2.7 ,我们需要的是 python3
![image-20200916115826385](assets/image-20200916115826385.png)
接下来会提示安装用于 python 语法检测的插件 `pylint`
### 5、安装 Code Runner
当重复执行文件的时,之前的输出在终端中不能清除,这可能会影响观看。使用 `code runner` 插件可以解决
1. 安装 Code Runner
![image.png](assets/11414906-77275177467c966b.png)
2. 配置 Run Code
再次打开配置文件 `settings.json` 文件添加如下内容,并按下 `Control + s` 保存
```json
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": true,
// 每次运行文件之前,保存当前文件
"code-runner.saveFileBeforeRun": true,
// 默认的语言
"code-runner.defaultLanguage": "python",
// 每次运行文件前 保存所有的文件
"code-runner.saveAllFilesBeforeRun": true,
// 设置 phthon3 解释器路径
"code-runner.executorMap": {
"python": "/usr/local/bin/python3.8"
}
```
最终的配置文件
```json
{
"workbench.iconTheme": "vscode-icons",
"editor.fontSize": 30,
"debug.console.fontSize": 30,
"markdown.preview.fontSize": 26,
"terminal.integrated.fontSize": 30,
// 编辑的文件 每 1 秒自动保存一次
"files.autoSave": "afterDelay",
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.defaultLanguage": "python",
"code-runner.saveAllFilesBeforeRun": true,
// set python path
"code-runner.executorMap": {
"python": "/usr/bin/python3.8"
}
}
```
## 五、pycharm
### 1.过期刷新插件(可能不能用了)
添加插件仓库地址https://plugins.zhile.io然后搜索插件IDE Evarl Reset
![image-20240222093708703](assets/image-20240222093708703.png)
![image-20240222093751794](assets/image-20240222093751794.png)
2.汉化插件
插件页面搜索chinese