【发布时间】:2019-04-18 03:55:56
【问题描述】:
我遵循了有关设置 pyenv 工作流的指南,它包含一个 IPython 启动脚本,它在使用 Jupyter 时修改 PYTHONPATH。现在我不想使用 pyenv,但即使卸载了本指南中的所有内容。这种不受欢迎的脚本行为仍然存在。
我遵循了这个指南https://medium.com/@henriquebastos/the-definitive-guide-to-setup-my-python-workspace-628d68552e14。
它为 Jupyter 提供了一个单独的虚拟环境,供其他虚拟环境使用。它包含一个 IPython 启动脚本,该脚本运行并将 virtualenv 的站点包加载到 Jupyter Notebook 环境中。
我不再想使用 pyenv。我正在使用 MacOSX。我使用 Homebrew 安装 pyenv、pyenv-virtualenv、pyenv-virtualenvwrapper,所以我删除了所有使用“brew卸载”的。我从 /usr/local/bin、/usr/local/lib、/usr/local/share 和 ~/ 中删除了任何 pyenv、jupyter、ipython 和 python 的痕迹。
然后我再次使用自制软件安装了 python,并运行了pip3 install jupyter。我运行了 jupyter notebook,它仍在尝试从这个不存在的位置 '/Users/dhemming/.pyenv/versions/jupyter3/bin/python' 运行内核。
我真的不认为我理解那个脚本或 Python 路径,我真的希望有人能解释发生了什么。
按照指南,我这样做了:
创建 jupyter3 虚拟环境(以及其他虚拟环境):
pyenv virtualenv 3.6.0 jupyter3
安装 jupyter
pyenv activate jupyter3
pip install jupyter
python -m ipykernel install --user
pyenv deactivate
设置 pyenv 全局:
pyenv global 3.6.0 2.7.13 jupyter3 ipython2 tools3 tools2
检查哪个jupyter:
~$ pyenv which jupyter
/Users/dhemming/.pyenv/versions/jupyter3/bin/jupyter
安装 IPython 脚本:
ipython profile create
curl -L http://hbn.link/hb-ipython-startup-script > ~/.ipython/profile_default/startup/00-venv-sitepackages.py
这是 curl 命令获取的脚本:
import os
import sys
from warnings import warn
virtualenv = os.environ.get('VIRTUAL_ENV')
if virtualenv:
version = os.listdir(os.path.join(virtualenv, 'lib'))[0]
site_packages = os.path.join(virtualenv, 'lib', version, 'site-packages')
lib_dynload = os.path.join(virtualenv, 'lib', version, 'lib-dynload')
if not (os.path.exists(site_packages) and os.path.exists(lib_dynload)):
msg = 'Virtualenv site-packages discovery went wrong for %r' % repr([site_packages, lib_dynload])
warn(msg)
sys.path.insert(0, site_packages)
sys.path.insert(1, lib_dynload)
完成指南后一切正常,每当我使用 pyenv 创建新的虚拟环境时,它都会使用 jupyter3 虚拟环境来运行加载了新虚拟环境库等的笔记本。
然后我不再想要这个设置。因此,我删除了 python 的所有痕迹以及与 python 相关的任何内容,并使用 Homebrew 安装了一个新的 python 并执行 pip3 install jupyter。之后我运行jupyter notebook,我仍然得到这个:
Failed to run the command:
['/Users/dhemming/.pyenv/versions/jupyter3/bin/python', '-m', 'ipykernel_launcher', '-f', '/Users/dhemming/Library/Jupyter/runtime/kernel-1d721ce4-1619-498d-9f0b-62b98b12d0ac.json']
PATH='/usr/local/bin:/Users/dhemming/.rbenv/shims:/usr/local/opt/openssl/bin:/Users/dhemming/.nvm/versions/node/v8.11.2/bin:/Users/dhemming/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin'
with kwargs:
{'stdin': -1, 'stdout': None, 'stderr': None, 'cwd': '/Users/dhemming/workspace/tmp/tmp_01', 'start_new_session': True}
'/Users/dhemming/.pyenv/versions/jupyter3/bin/python' 来自哪里?
【问题讨论】:
标签: python jupyter-notebook ipython jupyter pyenv