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-1 python3]# cd /usr/local/python3 # 我的python3.6安装路径,如果没有python3⽬录应事先创建
# 依次执⾏如下命令
[root@ipha-dev71-1 python3]# wget /ftp/python/3.6.1/Python-3.
[root@ipha-dev71-1 python3]# tar -zxvf Python-3.
[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 下可查看软连接
[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-1 bin]# pip3 install configparser
Collecting configparser
Downloading /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 /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-1 python3]# whereis python3python默认安装路径
python3: /usr/bin/python3 /usr/local/python3
[root@ipha-dev71-1 python3]# which python3
/bin/python3
[root@ipha-dev71-1 python3]# find / -name python3
/
usr/bin/python3
/usr/local/python3
/usr/local/python3/Python-3.6.1/build/temp.linux-x86_64-3.6/usr/local/python3
/usr/local/python3/bin/python3
4.进⼊或退出python终端
[root@ipha-dev71-1 site-packages]# python3
Python 3.6.1 (default, Jan 252019, 14:39:36)
[GCC 4.8.520150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license"for more information.
>>> exit() # ctrl+d 也可以推出
5.升级pip3
[root@ipha-dev71-1 yysoft]# pip3 install --upgrade pip
6.执⾏python⽂件
[root@ipha-dev71-1 site-packages]# cd /root/.jenkins/workspace/python_proj
[root@ipha-dev71-1 python_proj]# ll
total 12
drwxr-xr-x 3 root root 84 Aug 1013:32 config
-rw-r--r-- 1 root root 1293 Aug 1013:23login.py
-rw-r--r-- 1 root root 1007 Aug 1013:23 request.py
-rw-r--r-- 1 root root 920 Aug 1013:23 run_method.py
[root@ipha-dev71-1 python_proj]# python3 run_method.py
{'code': '200', 'message': '登陆成功', 'data': {'uid': 13644, 'username': 'wangmm', 'password': None, 'us
erdesc': None, 'realname': '王萌萌', 'email': None, 'sex': None, 'age': None, 'officeQualification': None, 'title': None, 'zoneId': 331, 'zoneName
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论