PySe-001-基础环境配置(MacOX)
Python 是一种面向对象、解释型计算机程序设计语言,其源代码同样遵循 GPL(GNU General Public License)协议。Python语法简洁而清晰,具有丰富和强大的类库。由于Python语言的简洁、易读以及可扩展性,已成为广大攻城狮最受欢迎的程序设计语言之一。其在设计上坚持了清晰划一的风格,其编程语法有很强的限制性(缩进等),对没有良好编程习惯的攻城狮来说是一种局限,但对源码的规范和后期的维护却有着深远的益处。同时,Python 一种高级动态编程语言,是完全面向对象的语言。函数、模块、数字、字符串都是对象。并且完全支持继承、重载、派生、多继承,有益于增强源代码的复用性。Python支持重载运算符和动态类型。(更多 Python 的特性请自行联系 度娘 或者 谷大爷,谢谢!)
此文主要讲述 Python + Selenium 在 Mac OX 下的环境配置,敬请各位小主参阅。若有不足之处,敬请大神指正,非常感谢!
一、安装 Python
一般 MacOX 中自带,无需安装。若未安装,请自行到 Python 官网下载安装。官网链接:https://www.python.org/
执行命令 python -V 查看系统安装的 Python 版本,系统输出如下所示:
Python 2.7.6
二、安装 Python 基础包工具 setuptools
其对应的网址链接为:https://pypi.python.org/pypi/setuptools/
在控制台输入命令:curl https://bootstrap.pypa.io/ez_setup.py -o - | python,(需要联网)
asrh-3.2# curl https://bootstrap.pypa.io/ez_setup.py -o - | python % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11432 100 11432 0 0 11183 0 0:00:01 0:00:01 --:--:-- 11185 Extracting in /tmp/tmpIbCOJ1 Now working in /tmp/tmpIbCOJ1/setuptools-18.1 Installing Setuptools running install Checking .pth file support in /Library/Python/2.7/site-packages/ /usr/bin/python -E -c pass TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files 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.macosx-10.10-intel/egg running install_lib running build_py creating build creating build/lib copying easy_install.py -> build/lib creating build/lib/_markerlib copying _markerlib/__init__.py -> build/lib/_markerlib copying _markerlib/markers.py -> build/lib/_markerlib creating build/lib/pkg_resources copying pkg_resources/__init__.py -> build/lib/pkg_resources creating build/lib/setuptools copying setuptools/__init__.py -> build/lib/setuptools copying setuptools/archive_util.py -> build/lib/setuptools copying setuptools/compat.py -> build/lib/setuptools copying setuptools/depends.py -> build/lib/setuptools copying setuptools/dist.py -> build/lib/setuptools copying setuptools/extension.py -> build/lib/setuptools copying setuptools/lib2to3_ex.py -> build/lib/setuptools copying setuptools/msvc9_support.py -> build/lib/setuptools copying setuptools/package_index.py -> build/lib/setuptools copying setuptools/py26compat.py -> build/lib/setuptools copying setuptools/py27compat.py -> build/lib/setuptools copying setuptools/py31compat.py -> build/lib/setuptools copying setuptools/sandbox.py -> build/lib/setuptools copying setuptools/site-patch.py -> build/lib/setuptools copying setuptools/ssl_support.py -> build/lib/setuptools copying setuptools/unicode_utils.py -> build/lib/setuptools copying setuptools/utils.py -> build/lib/setuptools copying setuptools/version.py -> build/lib/setuptools copying setuptools/windows_support.py -> build/lib/setuptools creating build/lib/pkg_resources/_vendor copying pkg_resources/_vendor/__init__.py -> build/lib/pkg_resources/_vendor creating build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/__about__.py -> build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/__init__.py -> build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/_compat.py -> build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/_structures.py -> build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/specifiers.py -> build/lib/pkg_resources/_vendor/packaging copying pkg_resources/_vendor/packaging/version.py -> build/lib/pkg_resources/_vendor/packaging creating build/lib/setuptools/command copying setuptools/command/__init__.py -> build/lib/setuptools/command copying setuptools/command/alias.py -> build/lib/setuptools/command copying setuptools/command/bdist_egg.py -> build/lib/setuptools/command copying setuptools/command/bdist_rpm.py -> build/lib/setuptools/command copying setuptools/command/bdist_wininst.py -> build/lib/setuptools/command copying setuptools/command/build_ext.py -> build/lib/setuptools/command copying setuptools/command/build_py.py -> build/lib/setuptools/command copying setuptools/command/develop.py -> build/lib/setuptools/command copying setuptools/command/easy_install.py -> build/lib/setuptools/command copying setuptools/command/egg_info.py -> build/lib/setuptools/command copying setuptools/command/install.py -> build/lib/setuptools/command copying setuptools/command/install_egg_info.py -> build/lib/setuptools/command copying setuptools/command/install_lib.py -> build/lib/setuptools/command copying setuptools/command/install_scripts.py -> build/lib/setuptools/command copying setuptools/command/register.py -> build/lib/setuptools/command copying setuptools/command/rotate.py -> build/lib/setuptools/command copying setuptools/command/saveopts.py -> build/lib/setuptools/command copying setuptools/command/sdist.py -> build/lib/setuptools/command copying setuptools/command/setopt.py -> build/lib/setuptools/command copying setuptools/command/test.py -> build/lib/setuptools/command copying setuptools/command/upload_docs.py -> build/lib/setuptools/command copying setuptools/script (dev).tmpl -> build/lib/setuptools copying setuptools/script.tmpl -> build/lib/setuptools creating build/bdist.macosx-10.10-intel creating build/bdist.macosx-10.10-intel/egg creating build/bdist.macosx-10.10-intel/egg/_markerlib copying build/lib/_markerlib/__init__.py -> build/bdist.macosx-10.10-intel/egg/_markerlib copying build/lib/_markerlib/markers.py -> build/bdist.macosx-10.10-intel/egg/_markerlib copying build/lib/easy_install.py -> build/bdist.macosx-10.10-intel/egg creating build/bdist.macosx-10.10-intel/egg/pkg_resources copying build/lib/pkg_resources/__init__.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources creating build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor copying build/lib/pkg_resources/_vendor/__init__.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor creating build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/__about__.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/__init__.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/_compat.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/_structures.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/specifiers.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging copying build/lib/pkg_resources/_vendor/packaging/version.py -> build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging creating build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/__init__.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/archive_util.py -> build/bdist.macosx-10.10-intel/egg/setuptools creating build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/__init__.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/alias.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/bdist_egg.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/bdist_rpm.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/bdist_wininst.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/build_ext.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/build_py.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/develop.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/easy_install.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/egg_info.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/install.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/install_egg_info.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/install_lib.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/install_scripts.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/register.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/rotate.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/saveopts.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/sdist.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/setopt.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/test.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/command/upload_docs.py -> build/bdist.macosx-10.10-intel/egg/setuptools/command copying build/lib/setuptools/compat.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/depends.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/dist.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/extension.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/lib2to3_ex.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/msvc9_support.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/package_index.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/py26compat.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/py27compat.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/py31compat.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/sandbox.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/script (dev).tmpl -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/script.tmpl -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/site-patch.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/ssl_support.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/unicode_utils.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/utils.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/version.py -> build/bdist.macosx-10.10-intel/egg/setuptools copying build/lib/setuptools/windows_support.py -> build/bdist.macosx-10.10-intel/egg/setuptools byte-compiling build/bdist.macosx-10.10-intel/egg/_markerlib/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/_markerlib/markers.py to markers.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/easy_install.py to easy_install.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/__about__.py to __about__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/_compat.py to _compat.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/_structures.py to _structures.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/specifiers.py to specifiers.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/pkg_resources/_vendor/packaging/version.py to version.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/archive_util.py to archive_util.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/__init__.py to __init__.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/alias.py to alias.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/bdist_egg.py to bdist_egg.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/bdist_rpm.py to bdist_rpm.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/bdist_wininst.py to bdist_wininst.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/build_ext.py to build_ext.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/build_py.py to build_py.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/develop.py to develop.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/easy_install.py to easy_install.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/egg_info.py to egg_info.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/install.py to install.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/install_egg_info.py to install_egg_info.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/install_lib.py to install_lib.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/install_scripts.py to install_scripts.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/register.py to register.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/rotate.py to rotate.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/saveopts.py to saveopts.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/sdist.py to sdist.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/setopt.py to setopt.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/test.py to test.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/command/upload_docs.py to upload_docs.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/compat.py to compat.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/depends.py to depends.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/dist.py to dist.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/extension.py to extension.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/lib2to3_ex.py to lib2to3_ex.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/msvc9_support.py to msvc9_support.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/package_index.py to package_index.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/py26compat.py to py26compat.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/py27compat.py to py27compat.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/py31compat.py to py31compat.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/sandbox.py to sandbox.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/site-patch.py to site-patch.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/ssl_support.py to ssl_support.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/unicode_utils.py to unicode_utils.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/utils.py to utils.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/version.py to version.pyc byte-compiling build/bdist.macosx-10.10-intel/egg/setuptools/windows_support.py to windows_support.pyc creating build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/PKG-INFO -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/SOURCES.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/dependency_links.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/entry_points.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/requires.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/top_level.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO copying setuptools.egg-info/zip-safe -> build/bdist.macosx-10.10-intel/egg/EGG-INFO creating dist creating 'dist/setuptools-18.1-py2.7.egg' and adding 'build/bdist.macosx-10.10-intel/egg' to it removing 'build/bdist.macosx-10.10-intel/egg' (and everything under it) Processing setuptools-18.1-py2.7.egg Copying setuptools-18.1-py2.7.egg to /Library/Python/2.7/site-packages Adding setuptools 18.1 to easy-install.pth file Installing easy_install script to /usr/local/bin Installing easy_install-2.7 script to /usr/local/bin Installed /Library/Python/2.7/site-packages/setuptools-18.1-py2.7.egg Processing dependencies for setuptools==18.1 Finished processing dependencies for setuptools==18.1
三、安装Python 安装包管理工具 pip
pip 对应的网址为:https://pypi.python.org/pypi/pip
pip 自 python 2.7.9(含)和 Python 3.4(含)之后的版本中均已经包含了 pip,若是您安装了此版本,则无需再次安装 pip,请知悉!
下载 get-pip.py 对应链接为:https://bootstrap.pypa.io/get-pip.py ,下载完后执行命令 python get-pip.py,将会安装 pip,出现以下信息后,说明成功安装 pip。
asrh-3.2# python get-pip.py /tmp/tmppUtgRW/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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. Collecting pip /tmp/tmppUtgRW/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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. Downloading pip-7.1.0-py2.py3-none-any.whl (1.1MB) 100% |████████████████████████████████| 1.1MB 436kB/s Collecting wheel Downloading wheel-0.24.0-py2.py3-none-any.whl (63kB) 100% |████████████████████████████████| 65kB 5.4MB/s Installing collected packages: pip, wheel Successfully installed pip-7.1.0 wheel-0.24.0 asrh-3.2#
若是安装 pip 时未安装 setuptools,get-pip.py 也会安装 setuptools,无需担心。
pip 常用示例:
// 升级 setuptools pip install -U setuptools // 升级 pip pip insatll -U pip
四、安装 selenium
执行命令 pip install -U selenium,会联网下载最新的 selenium 并安装到系统,出现如下信息说明 selenium 安装成功。
asrh-3.2# pip install -U selenium Collecting selenium /Library/Python/2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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 selenium-2.47.1.tar.gz (2.6MB) 100% |████████████████████████████████| 2.6MB 141kB/s Building wheels for collected packages: selenium Running setup.py bdist_wheel for selenium Stored in directory: /var/root/Library/Caches/pip/wheels/b8/de/0c/fe6b68ad83ebf436a0db04431f8f7ca4d8bb44ab342133d9b3 Successfully built selenium Installing collected packages: selenium Successfully installed selenium-2.47.1 asrh-3.2#
至此, PySe-001-基础环境配置(MacOX) 顺利完结,希望此文能够给初学 Python 2.7.6 + Selenium 2.47.1 的您一份参考。
最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^
欢迎 【 留言 || 关注 || 打赏 】 。您的每一份心意都是对我的鼓励和支持!非常感谢!欢迎互加,相互交流学习!
作者:范丰平,本文链接:https://www.cnblogs.com/fengpingfan/p/4707639.html
Copyright @范丰平 版权所有,如需转载请标明本文原始链接出处,严禁商业用途! 我的个人博客链接地址:http://www.cnblogs.com/fengpingfan