背景
最近需要在 m1 mac 上用 scrapy 爬点数据,用 miniconda 装了个虚拟环境后,运行 scrapy shell 测试 https 请求时,报错如下:
builtins.MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks 
于是尝试了网上各种解决方案:
brew 简介
homebrew(简称brew)是macos下的一个包管理工具,相当于linux里的 apt-get 或者 yum 。
官网:https://brew.sh/ 国内源:https://gitee.com/cunkai/HomebrewCN
brew 安装
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
执行上述命令(我选的清华源),最后重启终端即可。 brew 主体安装在了 /opt/homebrew 中,用 brew 安装的包在 /opt/homebrew/Cellar 
brew 常用命令
- 查看帮助:
brew help <包名> , 或 brew -h 查看全局帮助 - 查看brew版本:
brew -v - 查询可用包:
brew search <包名> ,也可去 brew官网 查询 - 安装包:
brew [cask] install <包名> ,eg:brew install python@3.10 - 卸载包:
brew uninstall <包名> ,eg:brew uninstall python@3.10 - 查询已安装包列表:
brew list - 查看包信息:
brew info <包名> - 更新brew本身:
brew update
解决 scrapy 的问题
参考第一部分提到的解决方案和 blog ,按照以下步骤解决了问题:
- 用 brew 安装 python 3.10,
brew install python@3.10 。  装完会在 opt/homebrew/Cellar 下面产生如下文件(这一步目的可能是安装匹配 python 3.10 的 openssl@1.1 ? )  - 用 conda 安装 python 3.10.14 环境:
conda create -n spiderenv_py310 python=3.10 ,并进入到环境。 - 安装 scrapy,
pip install scrapy 。
测试一下:scrapy shell https://www.amazon.co.jp/dp/B09SLG3J6C  成功解决!最后附上 python 版本和 scrapy、pyopenssl、requests 等https相关的 package 版本信息,仅供参考。 
|