Python及模块的安装

Python源码安装

  • 下载
    $ wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz
    
  • 编译
    $ tar -xzvf Python-3.6.10.tgz
    $ cd Python-3.6.10
    $ ./configure --prefix=/usr/local
    $ make
    
  • 安装
    $ sudo make install
    

Python版本OpenCV的安装与卸载

  • 安装指定版本OpenCV
    $ pip3 install opencv_python==4.1.0.25
    
    如果出现错误提示,指定的版本未找到,则从提示信息中找到可用的版本,将“==”后面的版本号修改为可用的版本号。
  • 卸载
    • Linux
    $ sudo pip3 uninstall opencv-python
    
    • Windows
      以管理员身份运行cmd
    $ pip3 uninstall opencv-python
    
  • 查看opencv版本
    import cv2
    cv2.__version__
    

离线安装模块

  • 下载离线安装文件
    pip freeze > requirements.txt
    pip download -r requirements.txt -d ./packages
    
  • 安装
    将下载的离线安装文件拷至要安装的计算机中,执行以下命令安装:
    pip install --no-index --find-links=d:\software\packages -r requirements.txt 
    

离线安装pip和setuptools

  • python
    • 下载安装包
      https://pypi.org/project/pip/#files
    • 安装
      python -m pip install --upgrade pip-20.0.2-py2.py3-none-any.whl
      
      其中,pip-20.0.2-py2.py3-none-any.whl为pip安装包,不同版本其文件名不同。
  • setuptools
    • 下载安装包
      https://pypi.org/project/setuptools/
    • 安装
      pip install setuptools-46.1.3.whl
      
      其中,setuptools-46.1.3.whl为安装包文件名,不同版本其文件名中的版本号也不同。
    • 查看版本号
      通过以下命令可查看setuptools的版本号。
      easy_install --version
      

修改下载源为国内源

  • Windows
    • 在User的用户名目录下创建pip目录,如:C:\Users\Username\pip
    • 在该目录下新建文件pip.ini,并在该文件中添加以下内容
      [global]
      index-url = https://pypi.tuna.tsinghua.edu.cn/simple
      
  • Linux
    • 编辑~/.pip/pip.conf
      sudo vim ~/.pip/pip.conf
      
    • 在pip.conf中添加
      [global]
      index-url = https://pypi.tuna.tsinghua.edu.cn/simple
      [install]
      trusted-host = https://pypi.tuna.tsinghua.edu.cn
      
    • 保存并退出

问题及解决

  • 问题:安装时出现错误提示Could not find a version that satisfies the requirement torch==1.0.1
    解决方法
    pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m-win_amd64.whl
    
  • 问题:使用pip安装模块时出现错误提示could not find a version that satifies the requirement "setuptools",或No matching distribution found for setuptools>= 38.2.5,或Could not find a version that satisfies the requirement wheel (from versions: ) No matching distribution found for wheel
    解决方法:有两种解决方法:
    • 下载安装相应版本的setuptools或wheel,然后将其拷到要安装的模块所在目录,再执行批量安装。
    • 模块所在的目录缺少模块文件,可使用pip download根据列表文件重新下载模块。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值