一、python 虚拟环境[virtualenv/virtualenvwrapper]设置
1、介绍
1.virtualenv
virtualenv 是一个可以在同一计算机中隔离多个python版本的工具。能够:
- 在没有权限的情况下安装新套件
- 不同应用可以使用不同的套件版本
- 套件升级不影响其他应用
2.virtualenvwrapper
virtualenvwrapper是virtualenv的扩展管理包,用于更方便管理虚拟环境,它可以做:
- 将所有虚拟环境整合在一个目录下
- 管理(新增,删除,复制)虚拟环境
- 切换虚拟环境
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关闭多行,提示的可以按箭头→补全,或者箭头↓选择;