操作系统:Ubuntu 16.04
python 2.7
pip list | grep gev
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
gevent (1.3a2)
为了确保,我检查了:
pip install --upgrade gevent
Requirement already up-to-date: gevent in /home/user/.local/lib/python2.7/site-packages
Requirement already up-to-date: greenlet>=0.4.13; platform_python_implementation == "CPython" in /home/user/.local/lib/python2.7/site-packages (from gevent)
但是,当我实际运行我的 python 程序时,它会因错误而退出:
import gevent
ImportError: No module named gevent
请指教。
我已经尝试过的东西:
pip --version
pip 9.0.1 from /home/user/.local/lib/python2.7/site-packages (python 2.7)
python -m pip install --user gevent
Requirement already satisfied: gevent in /home/user/.local/lib/python2.7/site-packages
Requirement already satisfied: greenlet>=0.4.13; platform_python_implementation == "CPython" in /home/user/.local/lib/python2.7/site-packages (from gevent)
which -a python
/usr/bin/python
/usr/bin/python
连同这里提到的事情:
https://github.com/PokeAlarm/PokeAlarm/issues/22
我还尝试卸载 pip 安装并执行 apt-get :
sudo apt-get install python-gevent python-gevent-websocket
这里提到:https://askubuntu.com/questions/836029/importerror-no-module-named-gevent/1013457#1013457
最佳答案
在 Ubuntu 16.04 的 Python 虚拟环境中工作,我得到以下结果:
$ python -m pip install gevent Requirement already satisfied: gevent in ./lib/python2.7/site-packages Requirement already satisfied: greenlet>=0.4.10 in ./lib/python2.7/site-packages (from gevent)
import gevent
worked successfully in my Python virtual environment, but it did not work outside of my Python virtual environment until I ran the following command:
sudo apt install python-gevent # also works in all currently supported versions of Ubuntu
说明:gevent 是一个基于协程的 Python 网络库。 gevent 使用 greenlet 在 libevent 事件循环之上提供高级同步 API。您还可以通过运行以下命令在所有当前支持的 Ubuntu 版本中为 Python 3.x 安装 python3-gevent:
sudo apt install python3-gevent
关于python-2.7 - 即使已安装,也没有名为 gevent 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49198346/