0

我正在尝试安装一个库并在 PyCharm 上运行它。尝试通过 PyCharm 安装它,但我无法安装,发生了一些错误:

Collecting Google-Search-API
Using cached Google-Search-API-1.1.13.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/5t/y8w_0_2j52l866cgl2p2q0nm0000gn/T/pycharm-packaging0.tmp/Google-Search-API/setup.py", line 15, in <module>
    with open("test_requirements.txt") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test_requirements.txt'

连同错误消息一起,有一个建议:

“尝试从系统终端运行此命令。确保使用为位于 '/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5' 的 Python 解释器安装的正确版本的 'pip' 。”

凉爽的。所以我去了终端,做了一个export PATH=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5:$PATH以确保 pip 将 lib 发送到正确的位置。

尝试后pip install Google-Search-API,一切似乎都很好:

MacBook-Air-2:~ santanna_santanna$ pip install Google-Search-API
Requirement already satisfied: Google-Search-API in /anaconda/lib/python2.7/site-packages

没有错误,一切都很酷。

所以我回到 PyCharm 并按照 [Google-Search-API GitHub][1] 中的建议输入:

import google

并得到:

ImportError: No module named 'google'

我一直在绞尽脑汁在 PyCharm 上安装和使用它。

注意:在完成export PATH=...终端后我做了 awhich python并且终端给我的答案是//anaconda/bin/python

编辑

试过sudo /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -m pip install Google-Search-API了,我得到的错误与 PyCharm 上的错误非常相似:

The directory '/Users/santanna_santanna/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/santanna_santanna/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting Google-Search-API
  Downloading Google-Search-API-1.1.13.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-build-j2qk3_00/Google-Search-API/setup.py", line 15, in <module>
        with open("test_requirements.txt") as f:
    FileNotFoundError: [Errno 2] No such file or directory: 'test_requirements.txt'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-j2qk3_00/Google-Search-API/
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
4

2 回答 2

1

根据其 PyPI 页面:https ://pypi.python.org/pypi/Google-Search-API,此包处于 alpha 状态,仅支持 Python 2 。这可能是它安装错误的原因。

我建议使用替代解决方案来查询 Google 搜索 API,或者如果您绝对必须使用此包,则切换到 Python 2。

于 2018-01-23T21:06:53.967 回答
1

也许你换了另一种可能,但是对于其他想要在 python3 中开发的人

安装包

unidecode (py -3.5 -m pip install unidecode)
selenium  (py -3.5 -m pip install selenium)
bs4       (py -3.5 -m pip install bs4)

然后插入以下命令(确保您已安装 git)

py -3.5 -m pip install git+https://github.com/abenassi/Google-Search-API/

命令:

py -3.5 -m pip

对于python 3.5版,如果您处理多个python版本,这是一种舒适的方法,因此它将从python 3.5目录调用pip

它是从 github repo 下载的,在这种情况下,我对丢失的 .txt 文件没有任何问题,对我来说非常适合

于 2018-01-23T21:37:25.747 回答