我在Mac上安装了带有Python 3内核的jupyter笔记本。我尝试使用命令python2 -m pip install ipykernel
安装Python 2内核,但出现以下错误:
Collecting ipykernel
Using cached ipykernel-4.6.1-py2-none-any.whl
Collecting jupyter-client (from ipykernel)
Using cached jupyter_client-5.1.0-py2.py3-none-any.whl
Collecting tornado>=4.0 (from ipykernel)
Using cached tornado-4.5.1.tar.gz
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
wb.build(autobuilding=True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 412, in run_egg_info
self.setup_py, self.name,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 387, in setup_py
import setuptools # noqa
File "/usr/local/lib/python2.7/site-packages/setuptools/__init__.py", line 10, in <module>
from setuptools.extern.six.moves import filter, map
File "/usr/local/lib/python2.7/site-packages/setuptools/setuptools/__init__.py", line 160, in <module>
monkey.patch_all()
File "/usr/local/lib/python2.7/site-packages/setuptools/setuptools/monkey.py", line 48, in patch_all
distutils.core.Command = setuptools.Command
AttributeError: 'module' object has no attribute 'Command'
有谁能告诉我问题出在哪里以及如何为python 2安装内核?
答案 0 :(得分:0)
假设您正在运行Anaconda,我认为在您的终端中输入以下命令可能有效
1)使用创建Python 2.7 conda env
conda create -n python2 python=2.7
2)从终端激活你的新环境。
source activate python2
3)将ipykernel安装到python2 env
中pip install ipykernel
4)将python2内核安装到ipython
中ipython kernel install --name python2
如果您没有运行Anaconda,请尝试本教程; Create isolated Jupyter ipython kernels with pyenv and virtualenv
如果您仍有问题,请在下方发表评论。