【发布时间】:2023-09-13 16:15:01
【问题描述】:
我正在尝试安装一个名为 Scrapy 的模块。我使用安装它
pip install Scrapy
我在 /usr/local/lib/python2.7/site-packages 中看到了“scrapy”文件夹,但是当我尝试在 Python 程序中导入它时,却说没有该名称的模块。关于为什么会发生这种情况的任何想法?
编辑:这是 pip 命令的输出:
Downloading/unpacking Scrapy
Downloading Scrapy-0.20.0.tar.gz (745kB): 745kB downloaded
Running setup.py egg_info for package Scrapy
no previously-included directories found matching 'docs/build'
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.2 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/site-packages (from Twisted>=10.0.0->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in /usr/local/lib/python2.7/site-packages (from w3lib>=1.2->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from zope.interface>=3.6.0->Twisted>=10.0.0->Scrapy)
Installing collected packages: Scrapy
Running setup.py install for Scrapy
changing mode of build/scripts-2.7/scrapy from 644 to 755
no previously-included directories found matching 'docs/build'
changing mode of /usr/local/bin/scrapy to 755
Successfully installed Scrapy
Cleaning up...
当我运行 /usr/local/bin/scrapy 时,我得到了命令的用法和可用的命令。我注意到我的 /usr/local/bin 中有一个 python2.7 和 python2.7-32,我记得因为 Mavericks 的问题安装了 32 位版本。
这是python /usr/local/bin/scrapy的输出:
Traceback (most recent call last): File "/usr/local/bin/scrapy", line 3, in <module> from scrapy.cmdline import execute ImportError: No module named scrapy.cmdline
还有head /usr/local/bin/scrapy:
#!/usr/local/opt/python/bin/python2.7 from scrapy.cmdline import execute execute()
【问题讨论】:
-
你是
import Scrapy还是import scrapy? -
我实际上都遇到了导入错误。
-
sys.path中是否有/usr/local路径? -
@Miles: 如果
/path/to/scrapy显示使用信息但python /path/to/scrapy引发ImportError,那么您的机器上至少有两个python可执行文件并且pip不会安装到默认值中一种可用作python。head /usr/local/bin/scrapy显示了什么? -
@Jud:“即使软件包本身没有安装在那里”是不正确的。
scrapyis 安装到/usr/local/opt/...中,否则scrapy命令将生成ImportError而不是使用信息。 @cm2's answer 提出了一种访问特定 python 可执行文件的简单方法。如果python2.7别名被定义为指向#!/usr/local/opt/python/bin/python2.7,那么将#!/usr/bin/env python2.7shebang 添加到任何包含import scrapy的Python 脚本中或从命令行启动python2.7就足够了。
标签: python import module scrapy