admin 管理员组

文章数量: 887021

py , line 2, in import requests ImportError: No module named requests

调用python脚本失败,直接报错找不到request模块,需要安装下该模块

Traceback (most recent call last):
File “./Test.py”, line 2, in
from Test import OpengooApi
File “./Test.py”, line 2, in
import requests
ImportError: No module named requests

解决方案
pip install requests

ubuntu python3/python2环境切换

高版本ubuntu18以上一般会默认使用python3环境。如果py脚本需要要用到python2的环境,那么可以安装python2.

py脚本中增加#!/usr/bin/python 头,支持python虚拟环境.
安装python2虚拟环境:

  sudo apt install python2python2 --versionsudo apt install python3-virtualenvcd ~virtualenv --python python2 .venv2#切换到python2环境,此后用pip install就安装到了python2的虚拟环境中了source .venv2/bin/activate

本文标签: PY line 2 in import requests ImportError No module named requests