文件在python2中可用,但在Python3中不可用

文件在python2中可用,但在Python3中不可用,python,request,Python,Request,我正在尝试编写这个python程序。我正在尝试将请求导入为 import requests 然后在终点站,我跑 python3 filename.py 我听到一个错误说 No module named 'requests' 然而,当我pip安装请求时,我得到 Requirement already satisfied: requests in /anaconda/lib/python2.7/site-packages 从这里我该怎么办?正如chrisz提到的,我必须执行pip3安装请求,

我正在尝试编写这个python程序。我正在尝试将请求导入为

import requests
然后在终点站,我跑

python3 filename.py
我听到一个错误说

No module named 'requests'
然而,当我pip安装请求时,我得到

Requirement already satisfied: requests in /anaconda/lib/python2.7/site-packages

从这里我该怎么办?

正如chrisz提到的,我必须执行pip3安装请求,它解决了问题

您的系统上运行两个版本的python,当您尝试运行pip时,它运行的是python 2.x版本而不是python 3.x版本,请尝试以这种方式运行pip

    py -3.x -m pip install requests 
其中x是安装在您的系统上的特定python版本(如3.4或3.5…)


这将为Python3.x版本安装请求

pip3安装请求
它甚至会告诉您在输出中满足了哪一个python版本的要求。但是,这不是对内存的低效使用吗?python2.7目录中的请求与pip3安装目录中的请求有何不同?@avishemondal Python 2和Python 3不兼容。Python2版本的
请求
模块是为Python2编写的,同样也为Python3版本编写的。如果您同时使用来自2和3的
请求
模块,则需要这两个模块。