首页 > 代码库 > 从零开始学Python-day1

从零开始学Python-day1

一、Linux系统的安装。


    本人计划安装CentOS6.X版本来学习Python。CentOS系统的下载地址【http://ftp.isu.edu.tw/pub/Linux/CentOS/6.8/isos/x86_64/CentOS-6.8-x86_64-bin-DVD2.iso】。具体的系统安装步骤不在详细介绍。

    遇到问题安装过程中遇到虚拟机报错error  processing drive其原因是虚拟机分配内存太小导致系统安装无法继续调整下内存大小将512M调整到适当大小即可。


二、升级安装Python2.7.9

    

1. xz -d Python-2.7.9.tar.xz      #将xz格式解压缩 ====>Python-2.7.9.tar

2. tar xf Python-2.7.9.tar        #打开归档       ====>Python-2.7.9 变成目录

3. cd Python-2.7.9                
   ./configure --prefix=/usr/local/python2.7.9      #安装三步骤
   make  &&  make install (记得使用echo $?检查)
   
 4. ln -s /usr/bin/python /usr/bin/python2.4.3                                #将旧版本python链接到别的地方
    ln -s /usr/local/python2.7.9/bin/python /usr/bin/python                   #将升级的python链接成为python
    
 5.  vim /usr/bin/yum将python替换为python2.4.3       #目的是使yum能够在旧的Python环境下继续使用


三、安装setuptools

1.  cd /usr/local/python2.7.9                         #进入到Python的安装目录下去

2.  tar xf setuptools-2.0.tar.gz                      #解压缩setuptools

3.  cd setuptools-2.0                                 #进入到setuptools的目录下

4.  python setup.py build                             #编译(echo $?检查)

5.  python setup.py install                           #安装

    ·遇到问题:RuntimeError: Compression requires the (missing) zlib module

 

copying setuptools.egg-info/zip-safe -> build/bdist.linux-i686/egg/EGG-INFO
creating dist
creating ‘dist/setuptools-2.0-py2.7.egg‘ and adding ‘build/bdist.linux-i686/egg‘ to it
Traceback (most recent call last):
  File "setup.py", line 200, in <module>
    dist = setuptools.setup(**setup_params)
  File "/usr/local/python27/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/python27/setuptools-2.0/setuptools/command/install.py", line 73, in run
    self.do_egg_install()
  File "/usr/local/python27/setuptools-2.0/setuptools/command/install.py", line 93, in do_egg_install
    self.run_command(‘bdist_egg‘)
  File "/usr/local/python27/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/python27/setuptools-2.0/setuptools/command/bdist_egg.py", line 246, in run
    dry_run=self.dry_run, mode=self.gen_header())
  File "/usr/local/python27/setuptools-2.0/setuptools/command/bdist_egg.py", line 545, in make_zipfile
    z = zipfile.ZipFile(zip_filename, mode, compression=compression)
  File "/usr/local/python27/lib/python2.7/zipfile.py", line 736, in __init__
    "Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module

    ·解决办法: 

yum install -y zlib zlib-devel

安装完成后,重新编译 python2.7【不需要删除,只需要重新编译,make,安装就行了】

在执行python setup.py install 即可安装成功。
[root@xiaowei setuptools-2.0]# python setup.py install 
running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file ‘setuptools.egg-info/SOURCES.txt‘
reading manifest template ‘MANIFEST.in‘
writing manifest file ‘setuptools.egg-info/SOURCES.txt‘
installing library code to build/bdist.linux-i686/egg
running install_lib
running build_py
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying setuptools.egg-info/requires.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO
creating ‘dist/setuptools-2.0-py2.7.egg‘ and adding ‘build/bdist.linux-i686/egg‘ to it
removing ‘build/bdist.linux-i686/egg‘ (and everything under it)
Processing setuptools-2.0-py2.7.egg
Copying setuptools-2.0-py2.7.egg to /usr/local/python27/lib/python2.7/site-packages
Adding setuptools 2.0 to easy-install.pth file
Installing easy_install script to /usr/local/python27/bin
Installing easy_install-2.7 script to /usr/local/python27/bin

Installed /usr/local/python27/lib/python2.7/site-packages/setuptools-2.0-py2.7.egg
Processing dependencies for setuptools==2.0
Finished processing dependencies for setuptools==2.0
[root@xiaowei setuptools-2.0]# echo $?
0
[root@xiaowei setuptools-2.0]#


四、安装pip.

    

1.cd /usr/local/python2.7.9/目录下,安装匹配(安装包为:pip-8.1.2.tar.gz)

    ·遇到问题:ImportError: cannot import name HTTPSHandler

解决办法: yum install -y  openssl openssl-devel
      
安装完成后,重新编译 python2.7【不需要删除,只需要重新编译,make,安装就行了】

在执行python setup.py install 即可安装成功。
      
测试如下:
[root@xiaowei pip-8.1.2]# /usr/local/python27/bin/pip install flask 
Collecting flask
  Downloading Flask-0.11.1-py2.py3-none-any.whl (80kB)
    100% |################################| 81kB 395kB/s 
Collecting Werkzeug>=0.7 (from flask)
  Downloading Werkzeug-0.11.11-py2.py3-none-any.whl (306kB)
    100% |################################| 307kB 870kB/s 
Collecting Jinja2>=2.4 (from flask)
  Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
    100% |################################| 266kB 1.0MB/s 
Collecting click>=2.0 (from flask)
  Downloading click-6.6.tar.gz (283kB)
    100% |################################| 286kB 1.2MB/s 
Collecting itsdangerous>=0.21 (from flask)
  Downloading itsdangerous-0.24.tar.gz (46kB)
    100% |################################| 51kB 2.6MB/s 
Collecting MarkupSafe (from Jinja2>=2.4->flask)
  Downloading MarkupSafe-0.23.tar.gz
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, click, itsdangerous, flask
  Running setup.py install for MarkupSafe ... done
  Running setup.py install for click ... done
  Running setup.py install for itsdangerous ... done
Successfully installed Jinja2-2.8 MarkupSafe-0.23 Werkzeug-0.11.11 click-6.6 flask-0.11.1 itsdangerous-0.24


五、使用pip安装ipython

   使用pip命令安装ipython: pip install ipython 

   pip命令的使用:pip的使用详解:http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

[root@xiaowei ~]# pip --help 

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user
                              configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output.
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5
                              times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe,
                              (b)ackup.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any
                              HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key
                              and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don‘t periodically check PyPI to determine whether a new version of pip
                              is available for download. Implied with --no-index.





本文出自 “11931192” 博客,谢绝转载!

从零开始学Python-day1