centOS7安装python3.6.5&python3创建虚拟环境教程

1、下载Python-3.6.5安装包

  • 在Python官网https://www.python.org/dowmloads/下载对应的安装包,选择3.6.5对应的linux版本

2、将安装包上传至Linux服务器

  • 在Linux服务器根目录下创建目录soft,并将安装包上传至该目录下

3、解压Python-3.6.5.tgz

  • [root@Cherry /]# cd /soft/
  • [root@Cherry soft]# tar -zxvf Python-3.6.5.tgz

4、创建Python-3.6.5安装目录

  • [root@Cherry soft]# mkdir /usr/local/python3

5、安装依赖包

  • [root@Cherry soft]# yum install -y gcc
  • [root@Cherry soft]# yum install -y zlib*
  • [root@Cherry soft]# yum install openssl openssl-devel
  • [root@Cherry soft]# 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

6、配置安装路径

  • [root@Cherry soft]# cd Python-3.6.5
  • [root@Cherry Python-3.6.5]# ./configure --prefix=/python3 注意这里一定要配置绝对路径

7、编译

  • [root@Cherry Python-3.6.5]# make

8、安装

  • [root@Cherry Python-3.6.5]# make install

9、建立软连接

  • [root@localhost Python-3.6.5]# ln -s /python3.6.5/bin/python3 /usr/bin/python3
  • [root@localhost Python-3.6.5]# ln -s /python3.6.5/bin/pip3 /usr/bin/pip3

10、增加环境变量

  • 修改配置文件:vi /etc/profile,增加以下内容并保存:
  • export PYTHON_HOME=/python3 (这是安装路径)
  • export PATH= P Y T H O N H O M E / b i n : PYTHON_HOME/bin: PYTHONHOME/bin:PATH (这里直接copy)
  • 执行语句source /etc/profile使环境变量配置立即生效

11、测试是否安装成功

  • [root@localhost Python-3.6.5]# python3
Python 3.6.5 (default, Oct 30 2019, 10:13:28) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

12、测试pip3是否可用

  • [root@localhost Python-3.6.5]# pip3

Usage:   
  pip  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  --log                 Path to a verbose appending log.
  --proxy              Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries          Maximum number of retries each connection should attempt (default 5 times).
  --timeout              Set the socket timeout (default 15 seconds).
  --exists-action     Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host    Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert                Path to alternate CA bundle.
  --client-cert         Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir            Store the cache data in .
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.

13、linux环境python3创建虚拟环境

  • 创建虚拟环境目录:python3 -m venv venv-python365 venv-python365为目录名,自定义即可
  • 激活虚拟环境:source venv-python365/bin/activate
  • 退出虚拟环境:deactivate

14、windows环境python3创建虚拟环境

  • 创建虚拟环境目录:python3 -m venv venv-python365 venv-python365为目录名,自定义即可
  • 激活虚拟环境:进入到venv-python365/scripts,然后执行activate,即可进入虚拟环境
  • 退出虚拟环境:deactivate

你可能感兴趣的:(运维)