我正在尝试安装一个名为 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
And head /usr/local/bin/scrapy
:
#!/usr/local/opt/python/bin/python2.7 from scrapy.cmdline import execute execute()
您使用的是 Homebrew 或 MacPorts 之类的吗?正如 @J.F.Sebastian 所说,听起来你在混合 OS X 附带的默认 python 和通过包管理器安装的 python 时遇到了问题......尝试/usr/local/opt/python/bin/python2.7 -m scrapy
看看是否会引发ImportError
.
如果这有效,那么您可能需要考虑制作thatpython 可执行文件是你的默认值。就像是alias python2.7=/usr/local/opt/python/bin/python2.7
然后总是使用python2.7
而不是默认的python
。你也可以直接点python
to the /urs/local...
位,但是如果您出于某种原因需要它,您将无法轻松访问系统(OS X 提供的)python。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)