没有名为fake useragen的模块

2024-04-19 23:29:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Github(here)上可用的PyTrends模块。要使用此脚本,我需要使用以下命令安装假用户代理模块:

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...

Tags: installpippybuildparserincludelinuxsetup
1条回答
网友
1楼 · 发布于 2024-04-19 23:29:28

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

如果你在Ubuntu上操作,请先运行这个

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

然后您就可以安装所需的python库了。

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

最良好的祝愿

相关问题 更多 >