如何为 Python3 安装散景

How to install bokeh for Python3

我通过 pip 安装了 bokeh,这里是安装的版本信息

pooja@X1-Carbon-6:~$ python3 --version
Python 3.5.2
pooja@X1-Carbon-6:~$ python --version
Python 2.7.12
pooja@X1-Carbon-6:~$ bokeh --version
0.13.0

对于 python2,它工作正常并且可以导入散景

lkhr@X1-Carbon-6:~notebooks$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
>>> 

但是,当我使用 python3

时它会报错
olkhr@X1-Carbon-6:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'bokeh'
>>> 

我想在我的 Python3 Jupyter-Notebook 中使用 bokeh 并且遇到问题,如果有任何建议,请告诉我。

非常感谢,

我在这里遇到了同样的问题。 显然,pip 安装存在一些问题。 我通过使用 conda 重新安装 bokeh 解决了我的问题。

这听起来微不足道,但您需要在同一环境(虚拟或非虚拟)下同时安装(jupyter notebook 和 bokeh)。

如果您使用 jupyter's website (pip3 install jupyter) 中的代码片段安装了 jupyter notebook,那么您已将其安装在非虚拟环境中,据我所知,您正在尝试导入装在虚拟机里的bokeh。

有两种解决方案:

  1. 你运行一切都在非虚拟环境下(这可能不是best/cleanest的选择):

    • 使用 pip3 install jupyter
    • 安装笔记本
    • 使用 pip3 install bokeh
    • 安装散景
    • 使用jupyter notebook启动笔记本(不激活虚拟环境
  2. 你运行一切在虚拟环境下:

    • 激活您的虚拟环境
    • 使用 python -m pip install jupyter
    • 安装笔记本
    • 使用 python -m pip install bokeh
    • 安装散景
    • 使用 jupyter notebook
    • 启动笔记本

您可以同时拥有两个版本的 pippip2pip3)。

此外 pip 可以链接到 pip2/python2pip3/python3

对我来说,pip 链接到 Python 3.xpip2 链接到 Python 2.7pip3Python 3.x:

$ pip -V
pip 9.0.3 from /usr/local/lib/python3.6/dist-packages/pip-9.0.3-py3.6.egg (python 3.6)

$ pip2 -V
pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

$ pip3 -V
pip 9.0.3 from /usr/local/lib/python3.6/dist-packages/pip-9.0.3-py3.6.egg (python 3.6)

Python 版本:

$ python -V
Python 2.7.12

$ python3 -V
Python 3.6.6

在这种情况下,您应该为 Python 的两个版本安装 bokeh:

pip3 install bokeh
pip2 install bokeh

测试:

$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
>>> 

$ python3
Python 3.6.6 (default, Jun 28 2018, 04:42:43) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
>>> 

[注意]:

参考以下链接安装两个版本的pip