没有模块名为fake useragent

时间:2015-11-04 08:34:49

标签: python

我尝试使用Github(here)上提供的PyTrends模块。要使用此脚本,我需要使用以下命令安装fake-useragent模块:

pip install fake-useragent

但是,每次导入文件并在控制台中尝试执行命令时,都会出现以下错误:

>>> from pytrends2.pyGTrends import pyGTrends
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pytrends2.py", line 18, in <module>
    from fake_useragent import UserAgent
ImportError: No module named fake_useragent

我尝试了不同的事情并没有运气。尝试确保依赖模块安装时:

pip install pyyaml ua-parser user-agents

...我得到以下内容:

abraham@abraham-Inspiron-3521:~$ sudo pip install pyyaml user-agents
Downloading/unpacking pyyaml
  Downloading PyYAML-3.11.tar.gz (248kB): 248kB downloaded
  Running setup.py (path:/tmp/pip_build_root/pyyaml/setup.py) egg_info for package pyyaml

Downloading/unpacking user-agents
  Downloading user_agents-1.0.1-py2-none-any.whl
Downloading/unpacking ua-parser (from user-agents)
  Downloading ua_parser-0.5.0-py2-none-any.whl (66kB): 66kB downloaded
Installing collected packages: pyyaml, user-agents, ua-parser
  Running setup.py install for pyyaml
    checking if libyaml is compilable
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/check_libyaml.c -o build/temp.linux-x86_64-2.7/check_libyaml.o
    build/temp.linux-x86_64-2.7/check_libyaml.c:2:18: fatal error: yaml.h: No such file or directory
     #include <yaml.h>
                      ^
    compilation terminated.

    libyaml is not found or a compiler error: forcing --without-libyaml
    (if libyaml is installed correctly, you may need to
     specify the option --include-dirs or uncomment and
     modify the parameter include_dirs in setup.cfg)

Successfully installed pyyaml user-agents ua-parser
Cleaning up...

1 个答案:

答案 0 :(得分:0)

您可能想先为Linux安装开发库。 确保已安装所有开发包。

如果您确实在Ubuntu上进行操作,请先运行此

sudo apt-get install gcc libyaml-dev libpython2.7-dev 

您将能够安装所需的python库。

pip install pyyaml ua-parser user-agents fake-useragent

最美好的祝愿