python - Macbook 上的 scrapy 错误 : Module 'tutorial' already exists

标签 python macos scrapy

安装scrapy后, 我使用“scrapy startproject 教程”开始,但它显示如下:

Icelesss-MacBook-Pro:tutorial iceless$ scrapy startproject tutorial
Error: Module 'tutorial' already exists

当我输入 import scrapy 时,它显示:

Icelesss-MacBook-Pro:~ iceless$ import scrapy
-bash: import: command not found
Icelesss-MacBook-Pro:~ iceless$ scrapy.item
-bash: scrapy.item: command not found
Icelesss-MacBook-Pro:~ iceless$ create scrapy.Item
-bash: create: command not found
Icelesss-MacBook-Pro:~ iceless$ items.py
-bash: items.py: command not found
Icelesss-MacBook-Pro:~ iceless$ cd tutorial
Icelesss-MacBook-Pro:tutorial iceless$ import scrapy
-bash: import: command not found

最佳答案

这应该是一个相对简单的修复。在某些平台上,安装 scrapy 时似乎没有创建符号链接(symbolic link),或者没有将 cli 工具添加到您的 $PATH 中。需要做的第一件事是找到当前 Python 和版本的位置:

$ which python
/opt/local/bin/python # your python location may be different

$ python -V
Python 3.6.5 # your version may be different (we need the first two digits)

获取 which python 命令的前两条路径并将其添加到:

/Library/Frameworks/Python.framework/Versions/3.6/bin/scrapy

所以你最终得到:

/opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/scrapy

现在最后一步是为 ~/.bash_profile 中的命令创建一个别名:

alias scrapy="/opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/scrapy"

I've created a Bash script which should (hopefully) automate this process:

scrapy_alias.sh

#!/bin/bash

a=$(command -v python)
b=$(python -V | grep -oE "\\d\\.\\d")
c="${a%/bin*}/Library/Frameworks/Python.framework/Versions/${b}/bin/scrapy"

printf "\\n# Scrapy alias\\nalias scrapy=\"${c}\"\\n" | sudo tee -a ~/.bash_profile

在终端运行脚本,然后将更改源到 ~/.bash_profile:

$ ./scrapy_alias.sh
$ . ~/.bash_profile

现在您应该可以开始教程了:

$ scrapy startproject tutorial

New Scrapy project 'tutorial', using template directory '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scrapy/templates/project', created in:
    /Users/Username/Desktop/Scrapy_Tutorial

You can start your first spider with:
    cd tutorial
    scrapy genspider example example.com

关于python - Macbook 上的 scrapy 错误 : Module 'tutorial' already exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50765651/

相关文章:

javascript - AJAX 和 Python 错误 - 请求的资源上不存在 'Access-Control-Allow-Origin' header

python - WTForm "OR"条件验证器? (电子邮件或电话)

python - Tensorflow tf.cond 遇到错误 : TypeError: Failed to convert object of type <class 'function' > to Tensor

macos - 如何衡量Mac应用程序的图形性能?

python - 知道如何使用 scrapy 访问此网址吗?

python - 用Scrapy抓取时可以设置条件吗?

python - 使用粒子群优化进行适当的编码

SwiftUI macOS - 创建可点击的超链接

使用 C 中的终端将内容从一个文件复制到另一个文件

python - 如何在字典中添加字典