美文网首页
macOS 搭建爬虫运行环境

macOS 搭建爬虫运行环境

作者: 风吹屁屁微微凉 | 来源:发表于2020-12-22 16:54 被阅读0次

    首先macOS是自带python环境的,尽管版本比较低,先不升级,看看能不能用

    1.进入终端,随便在github上找个爬虫脚本,运行,譬如python run.py,这时候一般会报错,

    如 ImportError: No module named requests

    原因:mac osx上默认没有安装requests库,需要安装requests

    2.安装requests库,用pip install requests,这时候还是会报错,pip: command not found

    3.需要安装pip,用curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py,然后运行sudo python get-pip.py,,这时候会有一段黄黄的警告

    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

    WARNING: The directory '/Users/esttian/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

    大致意思是,你机器上的python运行环境太老了,现在不维护了,需要更新,不理他

    4.pip安装好后,安装requests库,sudo pip install requests

    5.后面还会陆续有一些缺失库提示,缺啥装啥

    6.最后运行你想要的py,万事大吉

    如果没有万事大吉,那就是某些语法不兼容老版本的python了,把python弄一弄

    1.上Homebrew官网,拷贝/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)",然后报错

      homebrew-core is a shallow clone.

    To `brew update`, first run:

      git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

    This restriction has been made on GitHub's request because updating shallow

    clones is an extremely expensive operation due to the tree layout and traffic of

    Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you

    automatically to avoid repeatedly performing an expensive unshallow operation in

    CI systems (which should instead be fixed to not use shallow clones). Sorry for

    the inconvenience!

    大致意思,还是要升级,进入下一步

    2.  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow,

    升级完homebrew-core,继续第一步,完美Installation successful!

    3.用brew doctor检测一下,可能会有一些warning,问题不大的话,略过

    4.好,开始安装python3,用 brew install python3

    5.万事大吉

    相关文章

      网友评论

          本文标题:macOS 搭建爬虫运行环境

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