python2虚拟环境笔记+mycli使用

 

一、python 虚拟环境[virtualenv/virtualenvwrapper]设置

1、介绍

1.virtualenv

virtualenv 是一个可以在同一计算机中隔离多个python版本的工具。能够:

  1. 在没有权限的情况下安装新套件
  2. 不同应用可以使用不同的套件版本
  3. 套件升级不影响其他应用

2.virtualenvwrapper

virtualenvwrapper是virtualenv的扩展管理包,用于更方便管理虚拟环境,它可以做:

  1. 将所有虚拟环境整合在一个目录下
  2. 管理(新增,删除,复制)虚拟环境
  3. 切换虚拟环境

2、安装与配置

1.安装

yum install python-devel gcc libjpeg-devel zlib-devel python-virtualenv -y
pip install virtualenv

pip install virtualenvwrapper

安装成功后需要先source环境变量,然后才可以使用,查找位置在/usr/bin/目录下

[root@boyideyt ~]# find / -name "virtualenvwrapper.sh"
/usr/bin/virtualenvwrapper.sh

2.配置

  • 创建虚拟环境管理目录在~下
mkdir $HOME/.local/virtualenvs
  • 在~/.bashrc中添加行
  export VIRTUALENV_USE_DISTRIBUTE=1        #  总是使用 pip/distribute                                                                                   
  export WORKON_HOME=$HOME/.local/virtualenvs       # 所有虚拟环境存储的目录             
  if [ -e $HOME/.local/bin/virtualenvwrapper.sh ];then                                                                                                        
      source $HOME/.local/bin/virtualenvwrapper.sh                                                                                                         
  else if [ -e /usr/bin/virtualenvwrapper.sh ];then                                                                                                     
            source /usr/bin/virtualenvwrapper.sh                                                                                                        
       fi                                                                                                                                                     
  fi                                                                                                                                                          
  export PIP_VIRTUALENV_BASE=$WORKON_HOME                                                                                                                     
  export PIP_RESPECT_VIRTUALENV=true   
  • source
source ~/.bashrc

3、使用

virtualenv ~/shrink_venv
source ~/shrink_venv/bin/activate
使用命令解释
mkvirtualenv py_django创建一个虚拟环境
workon py_django使用一个虚拟环境
workon列出所有环境
deactivate退出环境
lsvirtualenv -b列出所有环境
  

二、mycli使用体验

1、安装

# 创建虚拟环境
mkvirtualenv mysql_venv

# 在新建的虚拟环境下,安装mycli
pip mycli

安装后pip列表如下:

2、使用

(mysql_venv) [root@boyideyt ~]# mycli --help
Usage: mycli [OPTIONS] [DATABASE]

  A MySQL terminal client with auto-completion and syntax highlighting.

  Examples:
    - mycli my_database
    - mycli -u my_user -h my_host.com my_database
    - mycli mysql://my_user@my_host.com:3306/my_database

Options:
  -h, --host TEXT               Host address of the database.
  -P, --port INTEGER            Port number to use for connection. Honors
                                $MYSQL_TCP_PORT.
  -u, --user TEXT               User name to connect to the database.
  -S, --socket TEXT             The socket file to use for connection.
  -p, --password TEXT           Password to connect to the database.
  --pass TEXT                   Password to connect to the database.
  --ssh-user TEXT               User name to connect to ssh server.
  --ssh-host TEXT               Host name to connect to ssh server.
  --ssh-port INTEGER            Port to connect to ssh server.
  --ssh-password TEXT           Password to connect to ssh server.
  --ssh-key-filename TEXT       Private key filename (identify file) for the
                                ssh connection.
  --ssl-ca PATH                 CA file in PEM format.
  --ssl-capath TEXT             CA directory.
  --ssl-cert PATH               X509 cert in PEM format.
  --ssl-key PATH                X509 key in PEM format.
  --ssl-cipher TEXT             SSL cipher to use.
  --ssl-verify-server-cert      Verify server's "Common Name" in its cert
                                against hostname used when connecting. This
                                option is disabled by default.
  -V, --version                 Output mycli's version.
  -v, --verbose                 Verbose output.
  -D, --database TEXT           Database to use.
  -d, --dsn TEXT                Use DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-dsn                    list of DSN configured into the [alias_dsn]
                                section of myclirc file.
  -R, --prompt TEXT             Prompt format (Default: "\t \u@\h:\d> ").
  -l, --logfile FILENAME        Log every query and its results to a file.
  --defaults-group-suffix TEXT  Read MySQL config groups with the specified
                                suffix.
  --defaults-file PATH          Only read MySQL options from the given file.
  --myclirc PATH                Location of myclirc file.
  --auto-vertical-output        Automatically switch to vertical output mode
                                if the result is wider than the terminal
                                width.
  -t, --table                   Display batch output in table format.
  --csv                         Display batch output in CSV format.
  --warn / --no-warn            Warn before running a destructive query.
  --local-infile BOOLEAN        Enable/disable LOAD DATA LOCAL INFILE.
  --login-path TEXT             Read this path from the login file.
  -e, --execute TEXT            Execute command and quit.
  --help                        Show this message and exit.

使用效果截图:

提示说,F3关闭多行,提示的可以按箭头→补全,或者箭头↓选择;

参考1: https://www.jianshu.com/p/44ab75fbaef2

参考2:https://www.mycli.net/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值