• pip安装requirements.txt 更换国内镜像 创建虚拟环境


     对于python2安装pyqt5:

    pip install python-qt5      -i   https://pypi.tuna.tsinghua.edu.cn/simple

    pip install -r requirements.txt

    conda install --channel https://conda.anaconda.org/anaconda    tensorflow   tensorflow-gpu   -y   

    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch     -y   

     //--------------------------------------------------------------

    列出已安装的包

    pip freeze or pip list

    导出requirements.txt

    pip freeze > <目录>/requirements.txt

    安装包

    在线安装

    pip install <包名> 或 pip install -r requirements.txt

    通过使用== >= <= > <来指定版本,不写则安装最新版

    requirements.txt内容格式为:

    安装本地安装包

        APScheduler==2.1.2
        Django==1.5.4
        MySQL-Connector-Python==2.0.1
        MySQL-python==1.2.3
        PIL==1.1.7
        South==1.0.2
        django-grappelli==2.6.3
        django-pagination==1.0.7

    pip install <目录>/<文件名> 或 pip install --use-wheel --no-index --find-links=wheelhouse/ <包名>

    <包名>前有空格

    可简写为

    pip install --no-index -f=<目录>/ <包名>

    卸载包

    pip uninstall <包名> 或 pip uninstall -r requirements.txt

    升级包

    pip install -U <包名>

    或:pip install <包名> --upgrade

    升级pip

    pip install -U pip

    显示包所在的目录

    pip show -f <包名>

    搜索包

    pip search <搜索关键字>

    查询可升级的包

    pip list -o

    下载包而不安装

    pip install <包名> -d <目录> 或 pip install -d <目录> -r requirements.txt

    打包

    pip wheel <包名>

    更换国内pypi镜像

    国内pypi镜像

    指定单次安装源

    pip install <包名> -i http://pypi.v2ex.com/simple

    指定全局安装源

    在unix和macos,配置文件为:$HOME/.pip/pip.conf
    在windows上,配置文件为:%HOME%pippip.ini

            [global]
            timeout = 6000
            index-url = http://pypi.douban.com/simple

    //-----------------------------------------------------------------------------------------------------

    python虚拟环境virtualenv创建及配置

    virtualenv

        用于创建一个隔离的python环境。可以有效解决版本冲突问题

    eric@userver:~$ python --version
    Python 2.7.12
    eric@userver:~$ python2 --version
    Python 2.7.12
    eric@userver:~$ python3 --version
    Python 3.5.2
    eric@userver:~$ python3.6 --version
    Python 3.6.3
    eric@userver:~$ 



     

        安装

        eric@userver:~$ sudo pip install virtualenv
    
        #如果报错 Command : pip can't found 输入
    
        eric@userver:~$ sudo apt-get install python-pip python-dev build-essential


     

        创建虚拟环境–指定版本进行创建

        eric@userver:~$ virtualenv -p python3.6 env3.6
        Running virtualenv with interpreter /usr/bin/python3.6
        Using base prefix '/usr'
        New python executable in /home/eric/env3.6/bin/python3.6
        Also creating executable in /home/eric/env3.6/bin/python
        Installing setuptools, pip, wheel...done.


          

        启动和退出虚拟环境

        #启用虚拟环境
    
        eric@userver:~$ source env3.6/bin/activate
        (env3.6) eric@userver:~$ #可以看到$PATH已经改变为env3.6
    
    
        #退出虚拟环境
    
        (env3.6) eric@userver:~$ deactivate
        eric@userver:~$
     
    
    virtualenvwrapper
    
    virtualenvwrapper 是一个基于virtualenv的工具,可以将所有的虚拟环境集中起来管理。
    
        安装
    
        $ sudo pip install virtualenvwrapper
         初始配置
        #直接使用命令启动
        $ source /usr/local/bin/virtualenvwrapper.sh
        #添加到shell启动文件~/.bash或者~/.profile
        #pyton virtual configure
        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/local/bin/virtualenvwrapper.sh ];then                          
                source /usr/local/bin/virtualenvwrapper.sh                             
           fi                                                                           
        fi                       
        export PIP_VIRTUALENV_BASE=$WORKON_HOME                       
        export PIP_RESPECT_VIRTUALENV=true
    
        #设置virtualenv别名
        alias vte='virtualenv'                                                           
        alias mkvte='mkvirtualenv'                                                       
        alias deact='deactivate'                                                         
        alias rmvte='rmvirtualenv'
    
        #使配置生效
        source ~/.bashrc

      ​
        使用方法
        1、帮助命令,查看所有 virtualenvwrapper –help
        2、创建基本环境:mkvirtualenv [环境名]
        3、激活环境:workon [环境名]
        4、删除环境:rmvirtualenv [环境名]
        4、退出环境:deactivate
        5、列出所有环境:workon

        创建python3.6环境

        $ mkvte -p python3.6 my_env3.6
        Running virtualenv with interpreter /usr/bin/python3.6
        Using base prefix '/usr'
        New python executable in /home/eric/.local/virtualenvs/my_env3.6/bin/python3.6
        Also creating executable in /home/eric/.local/virtualenvs/my_env3.6/bin/python
        Installing setuptools, pip, wheel...
        done.
    _________________________________________________________________________________________________________________________________________________
    每一个不曾起舞的日子,都是对生命的辜负。
    But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
    其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
  • 相关阅读:
    构造函数与其他方法的区别
    记录点复习题目和linux学习
    找点面试题目
    linux代码常用查询!!!!!!!!!!!!
    python复习
    明天面试今天赶紧准备下
    文都计算机考研课程
    是时候刷笔试题目了
    倒排索引
    总结算法课程
  • 原文地址:https://www.cnblogs.com/leoking01/p/14620584.html
Copyright © 2020-2023  润新知