美文网首页
linux 下python3 安装及虚拟环境搭建

linux 下python3 安装及虚拟环境搭建

作者: watson168 | 来源:发表于2017-11-29 15:01 被阅读46次
    1.下载并安装python
    [root@test82-devjenkins pkgs]#:wget -c https://www.python.org/ftp/python/3.3.7/Python-3.3.7.tgz
    [root@test82-devjenkins pkgs]# tar -xf Python-3.3.7.tgz
    [root@test82-devjenkins pkgs]#  cd Python-3.3.7
    [root@test82-devjenkins Python-3.3.7]# ./configure --prefix=/usr/local/python3
    [root@test82-devjenkins Python-3.3.7]#  make ; make install 
    [root@test82-devjenkins Python-3.3.7]# echo $?
    
    2.下载安装pip环境
    安装方法1
    [root@test82-devjenkins pkgs]# wget https://bootstrap.pypa.io/get-pip.py
    ###将get-pip.py中第一行的#!/usr/bin/env python替换成本地python3的地址/usr/local/python3/bin/python3
    [root@test82-devjenkins pkgs]# ./get-pip.py 
    [root@test82-devjenkins pkgs]# /usr/local/python3/bin/pip -V
    pip 9.0.1 from /usr/local/python3/lib/python3.3/site-packages (python 3.3)
    

    或者直接根据下面的方法


    安装方法2
    python3 -m pip install --user --upgrade pip
    
    3.安装python的虚拟环境

    (1)安装

    [root@test82-devjenkins pkgs]# /usr/local/python3/bin/pip install virtualenv
    [root@test82-devjenkins pkgs]# /usr/local/python3/bin/virtualenv --version
    15.1.0
    

    (2)创建

    [root@test82-devjenkins pkgs]# /usr/local/python3/bin/virtualenv  /home/ansible/.python3/
    

    (3)使用

    [root@test82-devjenkins pkgs]# source  /home/ansible/.python3/bin/activate
    (.python3) [root@test82-devjenkins pkgs]# python -V
    Python 3.3.7
    (.python3) [root@test82-devjenkins pkgs]# deactivate 
    [root@test82-devjenkins pkgs]# 
    
    python编程时设置环境变量为/home/ansible/.python3/bin/python 即可
    

    查看虚拟环境安装的Python 包

    
    pip list #查看安装的包
    pip freeze >requirements.txt
    

    参考链接:

    相关文章

      网友评论

          本文标题:linux 下python3 安装及虚拟环境搭建

          本文链接:https://www.haomeiwen.com/subject/dixyvxtx.html