我正在尝试安装一个库并在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'
与错误消息一起有一个提示:
"尝试从系统终端运行此命令。确保您 使用为您的 Python 解释器安装的正确版本的"pip" 位于 '/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5'.">
凉。所以我去了终端,做了一个export PATH=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5:$PATH
,以确保 pip 将库发送到正确的位置。
尝试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=...
后,我做了一个which 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.
根据其 PyPI 页面:https://pypi.python.org/pypi/Google-Search-API,该包处于 alpha 状态,仅支持 Python 2。这可能就是它安装错误的原因。
我建议使用替代解决方案来查询Google搜索API,或者如果您绝对必须使用此软件包,则切换到Python 2。
也许你换成了另一种可能性,但对于其他想要用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 存储库下载的,在这种情况下,我对丢失的 .txt 文件没有问题,非常适合我