首页 > 解决方案 > 安装 Python http 包时遇到问题

问题描述

我正在尝试将 Python http 包安装到我的 Mac 上的虚拟环境中,这样我就可以运行 Simple HTTP Server 但 pip 抱怨它无法从请求中导入请求:

% pip install http
...
ImportError: cannot import name 'Request' from 'request' (/Users/me/.virtualenvs/base/lib/python3.7/site-packages/request/__init__.py)

我最初安装了请求包,但这没有帮助。考虑到它可能需要请求,我也安装了它,但无济于事。

这是我的虚拟环境:

Package          Version  
---------------- ---------
certifi          2019.9.11
chardet          3.0.4    
get              2019.4.13
idna             2.8      
pip              19.3     
post             2019.4.13
powerline-status 2.7      
psycopg2-binary  2.8.3    
public           2019.4.13
query-string     2019.4.13
request          2019.4.13
requests         2.22.0   
setuptools       41.1.0   
urllib3          1.25.6   
wheel            0.33.4   

我在从 virtualenv 16.6.2 构建的虚拟环境中运行 Python 3.7.4。在 macOS Mojave 上。

标签: pythonpip

解决方案


您不必安装任何东西即可运行SimpleHTTPServerhttp在标准库中。

另请注意,这SimpleHTTPServerhttp.server在 Python 3 中调用的。


推荐阅读