为什么sklearn包在终端运行但不在jupyter中运行?

时间:2016-12-10 13:49:40

标签: python scikit-learn packages environment

在jupiter中导入sklearn时,结果为:

SELECT DISTINCT Product_Category_Mapping.CategoryId, Product.Id, Product.Name, Product.ShortDescription, Pvl_AdDates.Caption, Pvl_AdDates.EventDateTime, convert(varchar(25), Pvl_AdDates.EventDateTime, 120) AS TheDate, Pvl_AdDates.DisplayOrder, Pvl_Urls.URL, [Address].FirstName, [Address].LastName, [Address].Email, [Address].Company, [Address].City, [Address].Address1, [Address].Address2, [Address].ZipPostalCode, [Address].PhoneNumber 
FROM [Address] 
RIGHT JOIN (GenericAttribute  
RIGHT JOIN (Pvl_Urls RIGHT JOIN (Pvl_AdDates 
RIGHT JOIN (Product_Category_Mapping 
LEFT JOIN Product 
ON Product_Category_Mapping.ProductId = Product.Id) 
ON Pvl_AdDates.ProductId = Product.Id) 
ON Pvl_Urls.ProductId = Product.Id) 
ON GenericAttribute.EntityId = Product.Id) 
ON Address.Id = convert(int, GenericAttribute.Value) 
WHERE 
Product_Category_Mapping.CategoryId=12 
AND GenericAttribute.KeyGroup = 'Product'
AND Product.Published=1 
AND Product.Deleted=0 
AND Product.AvailableStartDateTimeUtc <= getdate() 
AND Product.AvailableEndDateTimeUtc >= getdate() 
ORDER BY 
Pvl_AdDates.EventDateTime DESC, 
Product.Id, 
Pvl_AdDates.DisplayOrder

我已经用pip安装了scikit-learn,并且pip list显示了sklearn的安装。导入sklearn完全在终端中工作,而不是在jupyter中。

我唯一的想法是他们在不同的环境中运行?

在终端:

>>> import sklearn
ImportError: No module named 'sklearn'

然而,在Jupyter:

>>> sys.executable
'/Users/Victoria/anaconda3/bin/python'

非常感谢任何帮助,非常感谢。

2 个答案:

答案 0 :(得分:4)

您可能需要安装相应的内核依赖项。执行以下命令。

pip install environment_kernels

现在重启你的Jupyter笔记本。 应该工作。

最佳!

答案 1 :(得分:3)

  • 激活您的环境,您应该看到以下内容:

    which python
    '/Users/Victoria/anaconda3/envs/py35/bin/python'
    which jupyter
    '/Users/Victoria/anaconda3/envs/py35/bin/jupyter'
    
  • 在环境中安装sklearn(您可以使用pip或conda)

  • 从环境中运行jupyter

如果这不起作用,请使用conda在您的环境中重新安装jupyter,然后重试。安装软件包后,您可能必须停用并激活一次环境。