linux下python相关命令

若本机已安装python2,尽量不要动现有的python2,额外安装python3即可。

1.安装python3.6(centos下安装python3自带pip和setuptools)

# 安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel [root@ipha-dev71- python3]# cd /usr/local/python3 # 我的python3.6安装路径,如果没有python3目录应事先创建
# 依次执行如下命令
[root@ipha-dev71-1 python3]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
[root@ipha-dev71-1 python3]# tar -zxvf Python-3.6.1.tgz
[root@ipha-dev71-1 python3]# /configure --prefix=/usr/local/python3   # 指定安装路径
[root@ipha-dev71-1 python3]# make
[root@ipha-dev71-1 python3]# make install
[root@ipha-dev71-1 python3]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3   # 建立软链接,同windows下的桌面快捷方式,可在/usr/bin 下可查看软连接

linux下python相关命令

[root@ipha-dev71-1 bin]# vim ~/.bash_profile   # 配置环境变量,~/.bash_profile指用户变量,/etc/profile指系统变量

添加如下内容

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH

[root@ipha-dev71-1 bin]# source ~/.bash_profile  # 使环境变量生效
[root@ipha-dev71-1 bin]# # ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 # 为pip3也创建软连接 # 检测是否安装成功

[root@ipha-dev71-1 bin]# python3 -V
   Python 3.6.1
  [root@ipha-dev71-1 bin]# pip3 -V
   pip 19.2.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)

2.安装第三方库(这里仅举个例子,其他第三方库可在用到时再进行安装)

[root@ipha-dev71- bin]# pip3 install configparser
Collecting configparser
Downloading https://files.pythonhosted.org/packages/09/4c/5e3ddf3cf1b457a25d48dc7253d0887c1037d79881942df5edd99cec4aca/configparser-3.7.5-py2.py3-none-any.whl
Installing collected packages: configparser
Successfully installed configparser-3.7.5

[root@ipha-dev71-1 report]# pip3 install pymysql
  Collecting pymysql
  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)
  |████████████████████████████████| 51kB 48kB/s
  Installing collected packages: pymysql
  Successfully installed pymysql-0.9.3

 pip list #查看已安装模块
pip search 模块名 #搜索模块

 3.linux查看python的几种方式

[root@ipha-dev71- python3]# whereis python3
python3: /usr/bin/python3 /usr/local/python3
[root@ipha-dev71- python3]# which python3
/bin/python3
[root@ipha-dev71- python3]# find / -name python3
/usr/bin/python3
/usr/local/python3
/usr/local/python3/Python-3.6./build/temp.linux-x86_64-3.6/usr/local/python3
/usr/local/python3/bin/python3

4.进入或退出python终端

[root@ipha-dev71- site-packages]# python3
Python 3.6. (default, Jan , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit() # ctrl+d 也可以推出

5.升级pip3

[root@ipha-dev71- yysoft]# pip3 install --upgrade pip

6.执行python文件

[root@ipha-dev71- site-packages]# cd /root/.jenkins/workspace/python_proj
[root@ipha-dev71- python_proj]# ll
total
drwxr-xr-x root root Aug : config
-rw-r--r-- root root Aug : login.py
-rw-r--r-- root root Aug : request.py
-rw-r--r-- root root Aug : run_method.py
[root@ipha-dev71- python_proj]# python3 run_method.py
{'code': '', 'message': '登陆成功', 'data': {'uid': , 'username': 'wangmm', 'password': None, 'userdesc': None, 'realname': '王萌萌', 'email': None, 'sex': None, 'age': None, 'officeQualification': None, 'title': None, 'zoneId': , 'zoneName': '南京鼓楼医院', 'state': None, 'createTime': None, 'createUserId': None, 'updateTime': None, 'updateUserId': None, 'endTime': None, 'lastLoginTime': None, 'remark': None, 'phone': None, 'py': None, 'datareportUser': None, 'company': None, 'userType': None, 'worknum': None, 'source': None}, 'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWFsTmFtZSI6IueOi-iQjOiQjCIsImlzcyI6ImlwaGFybWFjYXJlX2lzc3VlciIsInpvbmVJZCI6MzMxLCJleHAiOjE1NjU4MTc3MDksInVzZXJJZCI6MTM2NDQsImp0aSI6IndhbmdtbSJ9.msG4Spkmz0hk97vopJUJxSiad3qkvTdE2zHB8P1I6k8', 'refreshToken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWFsTmFtZSI6IueOi-iQjOiQjCIsImlzcyI6ImlwaGFybWFjYXJlX2lzc3VlciIsInpvbmVJZCI6MzMxLCJleHAiOjE1NjYxMTc3MDksInVzZXJJZCI6MTM2NDQsImp0aSI6IndhbmdtbSJ9.y3FNyspEgbXonY1FaCewdIAATYEwnWGYJu4-h2XataU', 'systemIsActive': , 'isXtss': None}
上一篇:转:基于TLS1.3的微信安全通信协议mmtls介绍


下一篇:sqlplus 配置方法及相关命令