python的pip 安装

python有很多好用的包,但是需要的时候一一安装实在是麻烦,还好有pip这么好用的安装工具。所以第一步是安装pip,然后其它软件都so easy!

文章来源:https://packaging.python.org/installing/#id11

Requirements for Installing Packages

This section describes the steps to follow before installing other Python packages.

Install pip, setuptools, and wheel

  • If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already havepip and setuptools, but will need to upgrade to the latest version:

    On Linux or OS X:

    pip install -U pip setuptools
    

    On Windows:

    python -m pip install -U pip setuptools
    
  • If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc...), and you want to use the system package manager to install or upgrade pip, then see Installing pip/setuptools/wheel with Linux Package Managers

  • Otherwise:

  • Securely Download get-pip.py [1]

  • Run python get-pip.py[2] This will install or upgrade pip. Additionally, it will install setuptoolsand wheel if they’re not installed already.

    Warning

    Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.

Optionally, Create a virtual environment

See section below for details, but here’s the basic commands:

Using virtualenv:

pip install virtualenv
virtualenv <DIR>
source <DIR>/bin/activate

Using venv[3]

python3 -m venv <DIR>
source <DIR>/bin/activate

Creating Virtual Environments

Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally.

Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtual environments can help you. They have their own installation directories and they don’t share libraries with other virtual environments.

Currently, there are two viable tools for creating Python virtual environments:

  • venv is available by default in Python 3.3 and later, and installs pip and setuptools into created virtual environments in Python 3.4 and later.
  • virtualenv needs to be installed separately, but supports Python 2.6+ and Python 3.3+, and pip,setuptools and wheel are always installed into created virtual environments by default (regardless of Python version).

The basic usage is like so:

Using virtualenv:

virtualenv <DIR>
source <DIR>/bin/activate

Using venv:

python3 -m venv <DIR>
source <DIR>/bin/activate

For more information, see the virtualenv docs or the venv docs.

Use pip for Installing

pip is the recommended installer. Below, we’ll cover the most common usage scenarios. For more detail, see the pip docs, which includes a complete Reference Guide.

There are a few cases where you might want to use easy_install instead of pip. For details, see the thepip vs easy_install breakdown in the Advanced Topics section.

Installing from PyPI

The most common usage of pip is to install from the Python Package Index using a requirement specifier. Generally speaking, a requirement specifier is composed of a project name followed by an optional version specifierPEP 440 contains a full specification of the currently supported specifiers. Below are some examples.

To install the latest version of “SomeProject”:

pip install 'SomeProject'

To install a specific version:

pip install 'SomeProject==1.4'

To install greater than or equal to one version and less than another:

pip install 'SomeProject>=1,<2'

To install a version that’s “compatible” with a certain version: [4]

pip install 'SomeProject~=1.4.2'

In this case, this means to install any version “==1.4.*” version that’s also “>=1.4.2”.

Upgrading packages

Upgrade an already installed SomeProject to the latest from PyPI.

pip install --upgrade SomeProject

python的pip 安装的更多相关文章

  1. 【pycharm】在pycharm上,使用python的pip安装tensorflow过程

    如题:在pycharm上,使用python的pip安装tensorflow过程 最后成功安装的版本信息是: python版本是3.6.5 pip版本是9.0.1 pycharm版本是2018.1 te ...

  2. python使用pip安装第三方模块遇到的问题及解决方法

    python使用pip安装第三方模块遇到的问题及解决方法 关注公众号"轻松学编程"了解更多. 使用国内源: 清华:https://pypi.tuna.tsinghua.edu.cn ...

  3. python使用pip安装模块出错 Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None))

    python使用pip安装模块出错 Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) 问题: ...

  4. python 之 PIP 安装

    1.安装的必备包 pip 和 setuptool 都要有, 这个可以从python.org网站下载 //  setuptool 安装  下载地址 https://pan.baidu.com/s/1gf ...

  5. Python中pip安装问题解决

    用国内镜像通过pip安装python的一些包,有时会出现安装失败, 为什么总是失败?自己操作老标准了,这么简单的几个小步骤还老是出错,不由得让我怀疑是否是撞墙了,可是又懒得买vpn去翻~~一墙,无法代 ...

  6. Python用pip安装IPython/Jupyter最佳交互环境

    一.Python模块及安装包简介 如果说编程语言是武器,那么Python就是一把双管枪(Python2/Python3),而各种为Python编写的模块和包就是子弹.使用pip来填满我们的武器吧! I ...

  7. 【python】pip安装报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 7: ordinal not in range(128)

    刚安装完python,准备pip安装第三方库的时候出现了一个错误: UnicodeDecodeError: ‘ascii’ code can’t decode byte 0xef in positio ...

  8. python之pip安装mysql-python失败

    前言 由于公司使用的python版本是python2,并且连接mysql的包是mysql-python,但是mysql-python 使用pip安装报错,需要C++环境等依赖,于是使用wheel直接安 ...

  9. Linux系统之路——python多版本共存问题(ps:自行切换python版本,pip安装遇到的一些问题)

    经常遇到这样的情况: 系统自带的Python是2.6,自己需要Python 2.7中的某些特性: 系统自带的Python是2.x,自己需要Python 3.x: 此时需要在系统中安装多个Python, ...

随机推荐

  1. js之定时器

    一.通过定时器我们可以间隔设定时间重复调用某个函数,利用这个特性,我们可以做很多事,例如,12306上的每间隔5秒查询自动查询一次余票,简单动画的实现等等 二.定时器的格式: 定时器有两种格式,分别是 ...

  2. 【Flask模板】include标签

    # include标签:1. 这个标签相当于是直接将指定的模版中的代码复制粘贴到当前位置.2. `include`标签,如果想要使用父模版中的变量,直接用就可以了,不需要使用`with context ...

  3. uboot 2013.01 代码简析(3)第二阶段初始化

    u-boot第二阶段初始化内容的入口函数是_main,_main位于arch/arm/lib/crt0.S文件中: _main函数中先为调用board_init_f准备初始化环境(设置栈指针sp和并给 ...

  4. 95th percentile concentration

    很多网络流量监控软件都提供了一个95th的值,开始一直不太理解,终于在solarwinds官网找到答案. 95th百分点指的是所给数集中超过其95%的数.它是一个统计学上的概念.对于某个接口,准确统计 ...

  5. Python—is和==

    首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识).type(数据类型)和value(值). ==是python运算符中的比较操作符,用来比较判断两个对象的value(值)是否相 ...

  6. PHP不用第三变量交换2个变量的值的解决方法

    以前做过一道php面试题是这样的:不使用第三个变量实现交换两个变量的值.一般都是借助第三个中间变量来实现原来两个变量的值交换,但是这道题却要求不能使用中间变量,这对于初学者来说也算是一个难题了.网上找 ...

  7. PyCharm 常用快捷键和设置

    pycharm常用快捷键 1.编辑(Editing) Ctrl + Space    基本的代码完成(类.方法.属性)Ctrl + Alt + Space  快速导入任意类Ctrl + Shift + ...

  8. Bootstrap-菜单,导航,按钮

    1.下拉菜单(基本用法) 在Bootstrap框架中的下拉菜单组件是一个独立的组件,根据不同的版本,它对应的文件: ☑  LESS版本:对应的源码文件为 dropdowns.less ☑  Sass版 ...

  9. docker 安装过程

  10. bzoj 2823: [AHOI2012]信号塔 最小圆覆盖

    题目大意: 给定n个点,求面积最小的园覆盖所有点.其中\(n \leq 10^6\) 题解: 恩... 刚拿到这道题的时候... 什么???最小圆覆盖不是\(O(n^3)\)的随机增量算法吗????? ...