learn python the hard way ----学习笔记(2)

     这一篇笔记, 主要是想解决一些困惑。

       learn python the hard  way 和 head frist python 都没有说清楚。

          知识点: 1,python sdist   

                          2, pip

                          3, distutils

                          4,setuptools

                          5, easy_install

                           6.distribute.

                          7.  python第三方包

                           8.  库包

                            9. mac目录

                            10.brew

                           11.curl 

                           12,OPEn命令




   (1) 困惑

                 第一: 什么是打包?  什么是发布?  



                       第二: 项目骨架有多少目录? 是干嘛用的?

                       第三: 第三方项目如何安装,发布,卸载,  在本地的什么地方可以查看?

                                      发布: pip install *

                                      卸载:  pip  uninstall *

                                      列表: pip  freeze

                                       有bin: which pip / pyspider 等。


                       第四:  如何查看第三方项目的说明

                                     这是一个需要补多问题 ,下一个比较补充。




                       第五:  setuptools ,Distutils,pip 是什么? 干嘛用的。

                                    distutils python包管理器,第一代, 原生python

                                    setuptools   python包管理器,第二代。。  

                                   pip  二代升级版。


                         第六; mac  /linux 系统  目录是什么样的。


           

cd / 
ls
(FINDER 中看到根目录,open / )

发现有  usr,  etc,  system,libray ,applications, dev,users, 用户信息。home等。


 这里面, 有个usr,  指的是unix system resouces,   而不是users,   苹果是unix系统, usr/bin ,  系统的可执行文件都在这,    usr/lcoal/bin   系统特定的可执行文件。





  (2)过程

                 我们都知道python2和python3的区别,但是我们可能弄不清楚这些软件包的历史, 写python书的作者各种习惯,也不会特意来解答这个问题,learn python the hard way 作者特别说这个过程叫 yak shaving. 


                    开始八卦史吧, python立国后, 当然有人掌,史官,叫:https://wiki.python.org/  ,利器吧。


            (1)  武术开山宗师

                     八卦史:

                    根据python江湖史,distutils 是武术开山宗家。 

                      家谱史是这么记载的:

                           Distutils is the standard mechanism to distribute Python packages and extensions since Python 1.6.

                        在 pyhon  1.6之前,Distutils(2000年发布)是发布python包的标准配置。  

                  

             功能:     distutils 是用来发布和安装python包的工具。

                    安装( 把python包安装到本机环境下):

                           

python setup.py install

                  发布(打包成tar或者zip):

python setup.py sdist

            有没有卸载包?

                       没有。


    (2)  王侯将相宁有总乎

            distutils 在发布之后, 也没想到自己这么一路逆袭,  丫就没想过可以成为大帝国, 人民的智慧总是updating了,  于是setuptools出来了,2013,setuptools起义了,不过真是陈胜,吴广,一群屌丝, 还是贵族内部的起义。

              setuptools 在新的帝国建立了, 分封了各种官。


              setuptools-----  easy_install   (  正仆射),用来安装,管理包,  但是这个时候, 他有了一个进步了,就是你可以直接从第三方安装包市场安装了,通俗一点,就是从python stroe下载包了。   

            

easy_install    包  
牛吧,  当然你可以

easy_intall  下载地址(如镜像)
         

   如果你想查看, easy_install版本 ,可以 easy_install  --v


   下面来说仆射了:

     ---- distribute (右仆射) : 有皇族血统, 曾经不臣之心, 最后还是老实做官了。
           这个就不做具体介绍了     ,但是如果是python3.x  ,  setuptools不支持3.*, 必须下载distribute.          

 

(3)江山代有人才出

             历史不管你愿意不愿意,总是不断刷新的, setuptools 后面出来了, 现在大名鼎鼎的pip, pip 当时只想取代easy_install, 。。 嘿嘿, 最后,,python 官方宣布python 3.4正式纳入pip,以后你就不需要下载pip了。

              

pip 介绍。

   安装: 

 $ pip install  ** 

 

列出安装的packages

$ pip freeze

 

卸载

 pin uninstall **


升级

pip  - U install ***


查看过期包

pip list --outdated


一般国外镜像比较慢, 建议用国内镜像


pip  install **  -i    http://pypi.douban.com/simple      (豆瓣pypi)

 

(3)实践   

           我们如果是网上下载包, 可以任意安装在放电脑, 但是这个时候一般是source.  就是有setup.py ,  需要python setup.py install (调用distutils), 如果pip intall... 的话,  好, 我们下载来安装一个包。

    pip install  pyspider 

   

lixiang ~ $ sudo pip install pyspider
Password:
The directory '/Users/lixiang/Library/Logs/pip' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/lixiang/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/lixiang/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyspider
/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pyspider-0.3.4.tar.gz (91kB)
    100% |████████████████████████████████| 94kB 284kB/s 
Collecting Flask>=0.10 (from pyspider)
  Downloading Flask-0.10.1.tar.gz (544kB)
    100% |████████████████████████████████| 544kB 291kB/s 
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.7 in /Library/Python/2.7/site-packages/Jinja2-2.7.3-py2.7.egg (from pyspider)
Collecting chardet>=2.2 (from pyspider)
  Downloading chardet-2.3.0.tar.gz (164kB)
    100% |████████████████████████████████| 167kB 1.1MB/s 
Collecting cssselect>=0.9 (from pyspider)
  Downloading cssselect-0.9.1.tar.gz
Collecting lxml (from pyspider)
  Downloading lxml-3.4.4.tar.gz (3.5MB)
    100% |████████████████████████████████| 3.5MB 90kB/s 
Collecting pycurl (from pyspider)
  Downloading pycurl-7.19.5.1.tar.gz (142kB)
    100% |████████████████████████████████| 143kB 1.1MB/s 
Collecting pyquery (from pyspider)
  Downloading pyquery-1.2.9.zip (45kB)
    100% |████████████████████████████████| 49kB 2.5MB/s 
Requirement already satisfied (use --upgrade to upgrade): requests>=2.2 in /Library/Python/2.7/site-packages/requests-2.5.1-py2.7.egg (from pyspider)
Collecting tornado>=3.2 (from pyspider)
  Downloading tornado-4.1.tar.gz (332kB)
    100% |████████████████████████████████| 335kB 293kB/s 
Collecting Flask-Login>=0.2.11 (from pyspider)
  Downloading Flask-Login-0.2.11.tar.gz
Collecting u-msgpack-python>=1.6 (from pyspider)
  Downloading u-msgpack-python-2.0.tar.gz
Collecting click>=3.3 (from pyspider)
  Downloading click-4.0-py2.py3-none-any.whl (62kB)
    100% |████████████████████████████████| 65kB 2.0MB/s 
Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pyspider)
Collecting Werkzeug>=0.7 (from Flask>=0.10->pyspider)
  Downloading Werkzeug-0.10.4-py2.py3-none-any.whl (293kB)
    100% |████████████████████████████████| 294kB 323kB/s 
Collecting itsdangerous>=0.21 (from Flask>=0.10->pyspider)
  Downloading itsdangerous-0.24.tar.gz (46kB)
    100% |████████████████████████████████| 49kB 2.5MB/s 
Requirement already satisfied (use --upgrade to upgrade): markupsafe in /Library/Python/2.7/site-packages/MarkupSafe-0.23-py2.7-macosx-10.10-intel.egg (from Jinja2>=2.7->pyspider)
Collecting certifi (from tornado>=3.2->pyspider)
  Downloading certifi-2015.04.28-py2.py3-none-any.whl (373kB)
    100% |████████████████████████████████| 376kB 797kB/s 
Collecting backports.ssl-match-hostname (from tornado>=3.2->pyspider)
  Downloading backports.ssl_match_hostname-3.4.0.2.tar.gz
Installing collected packages: Werkzeug, itsdangerous, Flask, chardet, cssselect, lxml, pycurl, pyquery, certifi, backports.ssl-match-hostname, tornado, Flask-Login, u-msgpack-python, click, pyspider
  Running setup.py install for itsdangerous
  Running setup.py install for Flask
  Running setup.py install for chardet
  Running setup.py install for cssselect
  Running setup.py install for lxml
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-rQTT_8/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-PLFb70-record/install-record.txt --single-version-externally-managed --compile:
    /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.4.4.
    Building without Cython.
    Using build configuration of libxslt 1.1.28
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.10-intel-2.7
    creating build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/__init__.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/_elementpath.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/builder.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/cssselect.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/doctestcompare.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/ElementInclude.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/pyclasslookup.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/sax.py -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/usedoctest.py -> build/lib.macosx-10.10-intel-2.7/lxml
    creating build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/__init__.py -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    creating build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/__init__.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/_diffcommand.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/_html5builder.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/_setmixin.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/builder.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/clean.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/defs.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/diff.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/ElementSoup.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/formfill.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/html5parser.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/soupparser.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    copying src/lxml/html/usedoctest.py -> build/lib.macosx-10.10-intel-2.7/lxml/html
    creating build/lib.macosx-10.10-intel-2.7/lxml/isoschematron
    copying src/lxml/isoschematron/__init__.py -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron
    copying src/lxml/lxml.etree.h -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/lxml.etree_api.h -> build/lib.macosx-10.10-intel-2.7/lxml
    copying src/lxml/includes/c14n.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/config.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/dtdvalid.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/etreepublic.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/htmlparser.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/relaxng.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/schematron.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/tree.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/uri.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xinclude.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xmlerror.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xmlparser.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xmlschema.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xpath.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/xslt.pxd -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/etree_defs.h -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    copying src/lxml/includes/lxml-version.h -> build/lib.macosx-10.10-intel-2.7/lxml/includes
    creating build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources
    creating build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/rng
    copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/rng
    creating build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl
    creating build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.macosx-10.10-intel-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    running build_ext
    building 'lxml.etree' extension
    creating build/temp.macosx-10.10-intel-2.7
    creating build/temp.macosx-10.10-intel-2.7/src
    creating build/temp.macosx-10.10-intel-2.7/src/lxml
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/usr/include/libxml2 -I/private/tmp/pip-build-rQTT_8/lxml/src/lxml/includes -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.10-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace
    In file included from src/lxml/lxml.etree.c:239:
    /private/tmp/pip-build-rQTT_8/lxml/src/lxml/includes/etree_defs.h:14:10: fatal error: 'libxml/xmlversion.h' file not found
    #include "libxml/xmlversion.h"
             ^
    1 error generated.
    error: command 'cc' failed with exit status 1
    
    ----------------------------------------
    Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-rQTT_8/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-PLFb70-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-rQTT_8/lxml

   看一下上面的过程,好对pythono有所了解。

    这一次安装失败来? 蛋疼, 又要找原因吗?

       仔细看,,代码, 不要因为是一串英文就怕了。

 In file included from src/lxml/lxml.etree.c:239:
    /private/tmp/pip-build-rQTT_8/lxml/src/lxml/includes/etree_defs.h:14:10: fatal error: 'libxml/xmlversion.h' file not found
    #include "libxml/xmlversion.h"
     表示libxml/xmlversion.h 却少,  这个情况百度一下,  你会发现。

      是这样的  , pyspider -----   依赖python包---- lxml,   而lxml  依赖库函数,,,   什么是库函数  ,  如果你玩过windows系统,  应该知道.net framework 缺少了,什么dll缺少了,没法玩游戏, 可以理解lxml, 要用到这一些,  这一些呢, 并不是python安装包, 所以你是无法pip intall.    

   lxml 依赖于库的---- libxml2, libxslt .  而这个安装是需要?

   安装库的软件包管理器----brew, 这个是需要下载的。

    有了之后,  brew  install  ***  就可以了。



 

  




你可能感兴趣的:(看书,python学习笔记)