超详细:command not found:scrapy解决办法(Mac下给zsh添加scrapy环境变量)

时间:2023-03-09 14:21:48
超详细:command not found:scrapy解决办法(Mac下给zsh添加scrapy环境变量)

背景:本来打算用scrapy 创一个爬虫项目,但是无论如何都显示zsh: command not found: scrapy,看了很多篇blog才解决了问题,决定记录一下。

主要参考的blog:

  1. https://www.jianshu.com/p/51196153f804

  2. https://*.com/questions/17607944/scrapy-not-installed-correctly-on-mac

问题分析:

我在重新安装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

  1. 打开finder,同时按下command+shift+g,输入.zshrc,打开.zshrc文件,然后在文件末尾写上source ~/.bash_profile

    超详细:command not found:scrapy解决办法(Mac下给zsh添加scrapy环境变量)
  2. 按下command+s 保存
  3. 打开终端,输入source ~/.zshrc,执行文件。

第二步:在.bash_profile文件中添加环境变量

  1. 打开finder,同时按下command+shift+g,输入.bash_profile,打开.bash_profile文件。
  2. 在最后一行写入:

    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"
  3. 按下command+s 保存。
  4. 打开终端,输入source ~/.bash_profile,执行文件。
  5. 最后可以在终端输入 echo $PATH看一下有没有将环境变量添加进去。超详细:command not found:scrapy解决办法(Mac下给zsh添加scrapy环境变量)
  6. 可以看到已经将/Library/Frameworks/Python.framework/Versions/2.7/bin添加进去了(而且还添加了很多个 )。
  7. 最后输入scapy终于可以使用了!!!

    超详细:command not found:scrapy解决办法(Mac下给zsh添加scrapy环境变量)