美文网首页
pip和apt-get

pip和apt-get

作者: wjv | 来源:发表于2019-03-08 22:26 被阅读0次

    来源:https://www.cnblogs.com/zxqstrong/p/4780251.html

    在ubuntu服务器下安装包的时候,经常会用到sudo apt-get install 包名 或 sudo pip install 包名,那么两者有什么区别呢?

    1.区别

    pip用来安装来自PyPI(https://www.python.org/)的python所有的依赖包,并且可以选择安装任何在PyPI上已上传的先前版本的依赖包,个人认为是python相关的包和第三方包以及各种版本;

    apt-get可以用来安装软件、更新源、也可以用来更新自Ubuntu(https://launchpad.net/ubuntu)的典型依赖包,典型安装即意味着它只是安装(最新发布的,或最近一个的)单一版本,并且我们不能决定我们要安装的依赖包的版本或选择它之前的版本。

    个人认为还是很好区分的:毕竟一个是更新系统级别包,一个是更新一种编程语言级别包(库)。

    2.使用

    情况是这样的,如果你需要最新版本的python依赖包,你可以直接使用apt-get,在项目突然需要使用旧版本的依赖包时,你就可以使用virtualenvwrapper和pip来使完美得再安装上一个旧版本的依赖包;

    你可以根据你的喜好选择你喜欢的安装方式。但是,如果你需要安装python包的特定版本,或在virtualenvwrapper中安装包,或安装只托管PyPI上一个包,此时只有pip会帮你解决这个问题了。否则,如果你不介意安装在系统范围的位置使用apt-get或pip都是ok的;

    3.安装及应用

    apt-get是可以直接使用的,格式为

    $ sudo apt-get install/delete package

    $ sudo apt-get -f install                                   #修复安装

    $ sudo apt-get dist-upgrade                                 #升级系统

    $ sudo apt-get upgrade                                      #更新已安装的包

    $ apt-get source package                                    #下载该包的源代码

    $ sudo apt-get build-dep package                            #安装相关的编译环境

    $ sudo apt-get clean && sudo apt-get autoclean              #清理无用的包

    pip需要安装才能使用,配合virtualenvwrapper会锦上添花。安装过程如下(适用Ubuntu 10.10及以上版本),使用格式为:pip install package。

    $ sudo apt-get install python-pip python-dev build-essential

    $ sudo pip install --upgrade pip

    $ sudo pip install --upgrade virtualenv


    来源:https://my.oschina.net/weiwubunengxiao/blog/402855

    pip install的源是pyPI,apt-get 的源是ubuntu仓库。

    对于python的包来说,pyPI的源要比ubuntu更多,对于同一个包,

    pyPI可以提供更多的版本以供下载。

    apt-get 安装的包是系统化的包,在系统内完全安装。

    pip install安装的python包,可以只安装在当前工程内

    apt-get 和 pip install 中,对于相同python包,命名可能会不同:

    apt-get install:对于python2来说,包的名称可能是python-

     对于python3来说,包的名称可能是python3-

    pip install:直接使用进行下载


    来源:https://askubuntu.com/questions/431780/apt-get-install-vs-pip-install

    PyPI is the Python Package index — repository of python modules.

    pip is used to download and install packages directly from PyPI. PyPI is hosted by Python Software Foundation. It is a specialized package manager that only deals with python packages.

    apt-get is used to download and install packages from Ubuntu repositories which are hosted by Canonical.

    Some of the differences between installing python packages from apt-get and pip are as follows:

    Canonical only provides packages for selected python modules. Whereas, PyPI hosts a much broader range of python modules. So, there are a lot of python modules which you won't be able to install using apt-get.

    Canonical only hosts a single version of any package (generally the latest or the one released in recent past). So, with apt-get we cannot decide the version of python-package that we want. pip helps us in this situation. We can install any version of the package that has previously been uploaded on PyPI. This is extremely helpful in case of conflict in dependencies.

    apt-get installs python modules in system-wide location. We cannot just install modules in our project virtualenv. pip solves this problem for us. If we are using pip after activating the virtualenv, it is intelligent enough to only install the modules in our project virtualenv. As mentioned in previous point, if there is a version of a particular python package already installed in system-wide location, and one of our project requires an older version of the same python package, in such situations we can use virtualenv and pip to install that older version of python package without any conflicts.

    As @Radu Rădeanu pointed out in this answer, there would generally be difference in names of packages as well. Canonical usually names Python 2 packages as python-<package_name> and Python 3 packages as python3-<package_name>. Whereas for pip we generally just need to use <package_name> for both Python 2 as well as Python3 packages.

    相关文章

      网友评论

          本文标题:pip和apt-get

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