背景:本来打算用scrapy 创一个爬虫项目,但是无论如何都显示zsh: command not found: scrapy
,看了很多篇blog才解决了问题,决定记录一下。
主要参考的blog:
问题分析:
我在重新安装scrapy时显示:
WARNING: The script scrapy is installed in
'/Library/Frameworks/Python.framework/Versions/3.9/bin' which is not on PATH.
Consider adding this directory to PATH
or, if you prefer to suppress this warning, use --no-warn-script-location.
说明/Library/Frameworks/Python.framework/Versions/3.9/bin
并不在PATH中,需要我们添加这个路径到环境变量里(Consider adding this directory to PATH )。
解决办法:
第一步:在.zshrc文件的末尾加上source ~/.bash_profile
。
- 打开finder,同时按下command+shift+g,输入.zshrc,打开.zshrc文件,然后在文件末尾写上
source ~/.bash_profile
。
- 按下command+s 保存
- 打开终端,输入
source ~/.zshrc
,执行文件。
第二步:在.bash_profile文件中添加环境变量
- 打开finder,同时按下command+shift+g,输入.bash_profile,打开.bash_profile文件。
- 在最后一行写入:
export PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH"
注意⚠️:Versions后的数字为python的版本号,要根据自己的python版本自行修改,如果版本为2.7则改为:
export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH"
- 按下command+s 保存。
- 打开终端,输入
source ~/.bash_profile
,执行文件。 - 最后可以在终端输入
echo $PATH
看一下有没有将环境变量添加进去。 - 可以看到已经将
/Library/Frameworks/Python.framework/Versions/2.7/bin
添加进去了(而且还添加了很多个)。 - 最后输入scapy终于可以使用了!!!