美文网首页
python包常用命令(不定时更新)

python包常用命令(不定时更新)

作者: whupenger | 来源:发表于2019-04-09 10:45 被阅读0次

    以下都是基于windows的命令,linux或者mac请在命令前面加上sudo

    检查python包是否过期

    • 列出所有的安装包
      pip list
    PS D:\Program Files\pytorchCache> pip list
    Package     Version
    ----------- -----------
    numpy       1.16.2
    Pillow      6.0.0
    pip         19.0.3
    setuptools  39.0.1
    six         1.12.0
    torch       1.0.1
    torchvision 0.2.2.post3
    
    • 列出所有的outdate包
      pip list --outdate
    PS D:\Program Files\pytorchCache> pip list --outdate
    Package    Version Latest Type
    ---------- ------- ------ -----
    setuptools 39.0.1  41.0.0 wheel
    
    • 更新某个包
      pip install --upgrade setuptools
    PS D:\Program Files\pytorchCache> pip install --upgrade setuptools
    Collecting setuptools
      Downloading https://files.pythonhosted.org/packages/c8/b0/cc6b7ba28d5fb790cf0d5946df849233e32b8872b6baca10c9e002ff5b41/setuptools-41.0.0-py2.py3-none-any.whl (575kB)
        100% |████████████████████████████████| 583kB 6.6MB/s
    Installing collected packages: setuptools
      Found existing installation: setuptools 39.0.1
        Uninstalling setuptools-39.0.1:
          Successfully uninstalled setuptools-39.0.1
    Successfully installed setuptools-41.0.0
    
    • 更新所有的包
      pip freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs -n1 pip install -U

    python源替换成国内源

    • unix内核
    vim ~/.pip/pip.conf
    //加上或者替换成阿里云镜像
    [global]
    trusted-host = mirrors.aliyun.com
    index-url = http://mirrors.aliyun.com/pypi/simple
    
    • windows
      在资源管理器输入%APPDATA%(C:\Users\Penger\AppData\Roaming),在该目录创建新的文件夹pip
      appdata
      进入pip,创建pip.ini文件,加入
    [global]
    index-url=http://mirrors.aliyun.com/pypi/simple/
     
    [install]
    trusted-host=mirrors.aliyun.com
    

    保存


    修改pip源

    Python导出本机安装环境

    pip freeze > packages.txt

    Python导入环境

    Python在linux下面创建虚拟环境

    • 进入自己的用户目录
      cd ~

    • 使用conda创建虚拟环境,可以指定虚拟环境的python版本号

      • 先确定是否安装conda,没有安装conda,需要先安装anaconda
        conda -V
      • 使用 wget下载anaconda
        wget -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
      • cd到anaconda安装包目录下,安装anaconda
        bash Anaconda3-5.3.1-Linux-x86_64.sh
      • 按enter浏览完协议以后,输入yes同意协议,选择安装路径的时候,按enter即可安装在默认目录下
      • 将conda加入path
        echo 'export PATH="/home/xxx/anaconda3/bin:$PATH"'>>~/.bashrc
        source ~/.bashrc
      • 开始创建虚拟环境,等待安装
        conda create -n [环境名] python==[python版本号]
      • 激活和关闭
        conda activate [环境名]
        conda deactivate
      • 删除指定环境名
        conda remove -n (环境名) --all
    • 进入虚拟环境之后,可以使用pip安装自己的python环境

    windows上的bash脚本在linux上换行编码不一致导致命令无法执行

    Unix系统里,每行结尾只有“<换行>”,即“\n”;Windows系统里面,每行结尾是“ <回车><换行>”,即“\r\n”;Mac系统里,每行结尾是“<回车>”。一个直接后果是,Unix/Mac系统下的文件在Windows里打开的话,所有文字会变成一行;而Windows里的文件在Unix/Mac下打开的话,在每行的结尾可能会多出一个^M符号

    • 使用sed命令,替换掉\r
      sed -i 's/\r//' xxx.sh && nohup bash xxx.sh >nohup.out 2>&1 &

    相关文章

      网友评论

          本文标题:python包常用命令(不定时更新)

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