导入无法正常运行的Python 3.7

时间:2018-11-11 00:48:01

标签: python pip python-requests

我正在运行带有Python 3.7的最新Kali Linux,并尝试使用请求模块。如您所见,我安装了请求,但仍无法导入。有人可以帮我解决这个奇怪的问题吗?

root@kali:~/Desktop# pip3 install --upgrade requests

Requirement already up-to-date: requests in 
/usr/local/lib/python3.7/site-packages (2.20.1)
Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 
in /usr/local/lib/python3.7/site-packages (from requests) (1.23)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests) (2018.10.15)
Requirement already satisfied, skipping upgrade: idna<2.8,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests) (2.7)

root@kali:~/Desktop# python3

Python 3.5.6 (default, Sep 29 2018, 21:41:04) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'requests'

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

由于似乎您安装了多个Python版本,因此您需要将环境设置为使用Python 3.7(当前设置为3.5.6,并且似乎未安装请求) )。

在您的.bash_profile中,您可以这样做:

alias python3=/path/to/python3.7

在输入python3时应使用3.7版本...