简体   繁体   English

如何为Python3安装bokeh

[英]How to install bokeh for Python3

I installed bokeh via pip and here is the information of the versions that are installed 我通过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

for python2, it works fine and could import bokeh 对于python2,它工作正常并且可以导入bokeh

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
>>> 

However, it complains when I use python3 但是,当我使用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'
>>> 

I want to use bokeh in my Python3 Jupyter-Notebook and having problem cos of this, if any suggestions are available, please let me know. 我想在我的Python3 Jupyter-Notebook中使用bokeh并对此有问题的建议,如果有任何建议,请告诉我。

Many thanks, 非常感谢,

It will sound trivial but you need to install both (jupyter notebook and bokeh) under the same environment (virtual or not). 这听起来很琐碎,但您需要在相同的环境(虚拟或非虚拟)下同时安装(jupyter笔记本电脑和bokeh)。

If you installed jupyter notebook using a snippet from the jupyter's website ( pip3 install jupyter ) then you have it installed in a non-virtual environment and from what I've understood you are trying to import bokeh which is installed in a virtual one. 如果您是使用jupyter网站上的一个片段( pip3 install jupyter )安装了jupyter笔记本,那么您已将其安装在非虚拟环境中,并且据我了解,您正在尝试导入安装在虚拟环境中的bokeh。

There are two solutions: 有两种解决方案:

  1. You run everything under non-virtual environment ( which is probably not the best/cleanest choice ): 您可以在非虚拟环境下运行所有​​内容( 这可能不是最佳/最干净的选择 ):

    • install the notebook using pip3 install jupyter 使用pip3 install jupyter笔记本pip3 install jupyter
    • install bokeh using pip3 install bokeh 使用pip3 install bokeh
    • start the notebook using jupyter notebook ( without activating virtual environment ) 使用jupyter notebook启动jupyter notebook不激活虚拟环境
  2. You run everything under virtual environment: 您可以在虚拟环境下运行所有​​内容:

    • activate your virtual environment 激活您的虚拟环境
    • install the notebook using python -m pip install jupyter 使用python -m pip install jupyter
    • install bokeh using python -m pip install bokeh 使用python -m pip install bokeh
    • start the notebook using jupyter notebook 使用jupyter notebook启动jupyter notebook

I had the same problem here. 我在这里有同样的问题。 Apparently, there are some problems with pip installation. 显然, pip安装存在一些问题。 I solved my problem with re-installing bokeh with conda . 我通过用conda重新安装bokeh解决了我的问题。

You can have both a different version of pip together ( pip2 , pip3 ). 您可以同时拥有两个不同版本的pippip2pip3 )。

And pip can be linked to whether pip2/python2 or pip3/python3 . pip可以链接到pip2/python2还是pip3/python3

For me pip is for Python 3.x , pip2 is for Python 2.7 and pip3 is for Python 3.x : 对我而言, pip适用于Python 3.xpip2适用于Python 2.7pip3适用于Python 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 versions: Python版本:

$ python -V
Python 2.7.12

$ python3 -V
Python 3.6.6

In this case, you should install bokeh for both versions of Python: 在这种情况下,您应该为两个版本的Python安装bokeh

sudo pip3 install bokeh
sudo pip2 install bokeh

Test: 测试:

$ 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
>>> 

[ NOTE ]: [ 注意 ]:

Refer to the following links to install both versions of pip : 请参考以下链接以安装两个版本的pip

You can also use conda instead of virtual-env and pip . 您也可以使用conda代替virtual-envpip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM