问题描述
我正在尝试为正在使用的笔记本计算机安装plotnine
.我已完成以下操作:
I am trying to install plotnine
for a notebook I am using. I have done the following:
-
使用python 3.6创建一个
conda
环境,并添加plotnine
在激活了上述环境的情况下启动jupyter lab
Launching jupyter lab
with the above environment activated
在笔记本中,我添加了以下行:!conda install -c conda-forge --yes plotnine
In the notebook, I added the following line:!conda install -c conda-forge --yes plotnine
但是,我的输出没有任何意义.首先说所有请求的软件包都已安装,然后说找不到模块
However, my output makes no sense. First it says that all requested packages have been installed, and then it says it cannot find the module
!conda install -c conda-forge --yes plotnine
from plotnine import *
Solving environment: done
# All requested packages already installed.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-386ef81e08ff> in <module>()
11 get_ipython().system('conda install -c conda-forge --yes plotnine')
12 ######
---> 13 from plotnine import * # python clone of ggplot2
14 matplotlib.rcParams['figure.figsize'] = [12, 8]
15 matplotlib.rcParams['lines.linewidth'] = 2
ImportError: No module named 'plotnine'
如果存在已知冲突,请参见完整的导入语句:
In case there is a known conflict, here is the entire import statement:
import gsc # proprietary module
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from ipywidgets import interact, FloatSlider
from util_demo import *
# adding installation of plotnine, which is not included by default
# import sys
!conda install -c conda-forge --yes plotnine
######
from plotnine import * # python clone of ggplot2
matplotlib.rcParams['figure.figsize'] = [12, 8]
matplotlib.rcParams['lines.linewidth'] = 2
matplotlib.rcParams['xtick.labelsize'] = 24
matplotlib.rcParams['ytick.labelsize'] = 24
matplotlib.rcParams['legend.fontsize'] = 24
matplotlib.rcParams['axes.labelsize'] = 24
编辑:我还检查了jupyter笔记本中的sys.path
并得到了以下内容.我在这里看不到有关conda
的任何信息.我应该更新PATH
还是PYTHONPATH
?
EDIT: I also checked sys.path
within the jupyter notebook and get the following. I do not see anything about conda
here. Should I update either PATH
or PYTHONPATH
?
['',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/extensions',
'/Users/adamg/.ipython']
推荐答案
我遇到了同样的问题.在我看来,我在Jupyter Lab中的笔记本运行的是基本内核,而不是虚拟环境的内核.键入
I had the same problem. It looks like for me, my notebook in Jupyter Lab was running the base kernel and not the kernel of the virtual environment. Type
import sys
sys.executable
插入笔记本.对我来说,我得到了结果
into your notebook. For me, I got the result
'/anaconda3/bin/python'
而不是期望的
'/anaconda3/envs/myenv/bin/python'
我按照 iPython文档.总而言之,您需要为新环境安装新的iPython内核.运行:
I solved it by following the instructions in the iPython documentation. In summary, you need to install a new iPython kernel for your new environment. Run:
conda install -n myenv ipython
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
然后,在新环境中运行Jupyter Lab:
Then, to run Jupyter Lab in the new environment:
conda activate myenv
jupyter lab
当您打开一个新笔记本时(也位于现有笔记本的右上角),您应该能够选择内核"Python(myenv)".
And you should be able to select the kernel "Python (myenv)" when you open a new notebook (also in the top right of an existing notebook).
这篇关于Jupyter Lab安装/导入软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!