没有模块名为fake useragent

ATM*_*TMA 5 python

我正在尝试使用PyTrendsGithub上提供的模块(这里).要使用此脚本,我需要安装fake-useragent模块:

pip install fake-useragent
Run Code Online (Sandbox Code Playgroud)

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

>>> 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
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的东西,没有运气.尝试确保安装依赖项模块时:

pip install pyyaml ua-parser user-agents
Run Code Online (Sandbox Code Playgroud)

......我得到以下内容:

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...
Run Code Online (Sandbox Code Playgroud)

Ste*_*ano 3

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

如果您确实在 Ubuntu 上运行,请尝试先运行此命令

sudo apt-get install gcc libyaml-dev libpython2.7-dev 
Run Code Online (Sandbox Code Playgroud)

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

pip install pyyaml ua-parser user-agents fake-useragent
Run Code Online (Sandbox Code Playgroud)

最好的祝愿