ImportError:没有使用两个版本的python

时间:2016-09-19 10:15:01

标签: python python-2.7 pip python-3.4

我安装了python 3.4.1,并且需要运行python 2脚本。我通过运行make install安装了python 2.7.5。当我运行我的脚本时,它写道:

Traceback (most recent call last):
  File "/root/roseltorg/run.py", line 2, in <module>
    import requests
ImportError: No module named requests

然后我尝试安装请求模块但是:

pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python3.4/site-packages/requests-2.11.1-py3.4.egg
Cleaning up...

如何强制为python 2.7安装此模块?

2 个答案:

答案 0 :(得分:1)

我更喜欢在这种情况下使用virtualenv。

virtualenv -p path_to_python2.7 .(current dir)
source bin/activate
pip install requests

答案 1 :(得分:1)

使用pip安装到python 3.4,这意味着pip指向pip3。尝试这样做

pip2 install requests