如何通过python3创建scrapy项目 [英] How to create the scrapy project by python3

查看:51
本文介绍了如何通过python3创建scrapy项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Mac OS,它有 python 2.7 和 python 3.4.我使用 pip install 命令在 python 2.7 中安装 scrapy.购买我也在python3.4中使用pip3 install命令安装scrapy...

I use Mac OS, it has python 2.7 and python 3.4. I use the pip install command to to install scrapy in python 2.7. Buy I also use the pip3 install command to install scrapy in python3.4 too...

我看了scrapy.org上的官方文档,我知道scrapy只支持python 2.7.当我使用命令 scrapy startproject tutorial 时,它会返回下面的错误.

I read the official documents on scrapy.org, I know that the scrapy just support the python 2.7. When I use the command scrapy startproject tutorial, it will return the errow below.

如何在 python 2.7 中使用命令 scrapy startproject tutorial?

How can I use the command scrapy startproject tutorial with python 2.7?

  File "/Library/Frameworks/Python.framework/Versions/3.4/bin/scrapy", line 9, in <module>
    load_entry_point('Scrapy==1.1.0dev1', 'console_scripts', 'scrapy')()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/Scrapy-1.1.0dev1-py3.4.egg/scrapy/cmdline.py", line 122, in execute
    cmds = _get_commands_dict(settings, inproject)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/Scrapy-1.1.0dev1-py3.4.egg/scrapy/cmdline.py", line 46, in _get_commands_dict
    cmds = _get_commands_from_module('scrapy.commands', inproject)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/Scrapy-1.1.0dev1-py3.4.egg/scrapy/cmdline.py", line 29, in _get_commands_from_module
    for cmd in _iter_command_classes(module):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/Scrapy-1.1.0dev1-py3.4.egg/scrapy/cmdline.py", line 21, in _iter_command_classes
    for obj in vars(module).itervalues():
AttributeError: 'dict' object has no attribute 'itervalues'

推荐答案

使用 pip 安装 scrapy 会将一个可执行文件放在您的 PATH 中的某处.由于你安装了两次,python2 版本可能被覆盖了.要查找此文件,请使用命令 which scrapy.要查看文件的内容,请使用 cat $(which scrapy).它可能包含一行,内容如下:#!/usr/bin/python3.4 导致它使用不兼容的 python 版本.

Installing scrapy with pip will put an executable file somewhere in your PATH. Since you installed it two times, the python2 version was probably overwritten. To find this file use the command which scrapy. To see the content of the file use cat $(which scrapy). It probably contains a line the reads something like this: #!/usr/bin/python3.4 causing it to use an incompatible version of python.

要解决此问题,请卸载 python3 版本的 scrapy.

To fix this, uninstall the python3 version of scrapy.

pip3 uninstall scrapy

然后使用 hash -r 或启动新的终端会话来清除 bash 中的命令缓存.

Then clean the command cache in bash by using hash -r or starting a new terminal session.

如果 scrapy 命令仍然不起作用,您可能还需要重新安装它的 python 2 版本.

If the scrapy command still doesn't work you might have to reinstall the python 2 version of it as well.

pip install scrapy --force-reinstall

这篇关于如何通过python3创建scrapy项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆