Macbook上的垃圾错误:模块“tutorial”已经存在

2024-10-04 01:35:44 发布

您现在位置:Python中文网/ 问答频道 /正文

安装完刮板后, 我使用“scrapy startproject tutorial”开始,但它显示了以下内容:

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

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

^{pr2}$

Tags: import刮板existserrortutorialproscrapymodule
1条回答
网友
1楼 · 发布于 2024-10-04 01:35:44

这应该是一个相对简单的解决方案。在某些平台上,安装scrapy时,似乎不会创建符号链接,或者不会将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命令的前两条路径,并将其前置为:

^{pr2}$

所以你的结局是:

/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:

发痒_别名.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

相关问题 更多 >