Dar*_*4GE 3 python linux archlinux jupyter jupyter-notebook
我希望能够在我的 Jupyter Notebook 中同时运行Python 3.8(当前版本)和Python 3.7。我知道从虚拟环境创建不同的 IPython 内核是一种方法。所以我下载了 Python 3.7 并将其本地安装在我的主目录中。使用这个 python 二进制文件来创建一个虚拟环境
> virtualenv -p ~/Python3.7/bin/python3 py37
> source py37/bin/activate
Run Code Online (Sandbox Code Playgroud)
这完美地工作,并在检查python --version和 时正确给出“Python 3.7” sys.version。然后为了创建 IPython 内核,
(py37) > ipython kernel install --user --name py37 --display-name "Python 3.7"
(py37) > jupyter notebook
Run Code Online (Sandbox Code Playgroud)
这也没有错误地运行,并且可以确认内核已添加到笔记本中。然而,它不像虚拟环境那样运行 Python 3.7,而是像默认内核那样运行 Python 3.8。(确认sys.version)
我检查~/.local/share/jupyter/kernels/py37/kernel.json并看到它的内容为
{
"argv": [
"/usr/bin/python3",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3.7",
"language": "python"
Run Code Online (Sandbox Code Playgroud)
所以很自然地,我尝试编辑/usr/bin/python3指向我的 Python 3.7 二进制文件路径~/Python3.7/bin/python3,但是即使内核在笔记本中也无法正常工作。
我能做什么?
注意:我使用Arch Linux,所以我安装了jupyter,virtualenv,...通过pacman而不是pip作为它在 Arch 中的推荐。
我自己找到了,很难。无论如何,让我分享一下,以防这对任何人有帮助。
我想,问题在于,通过pacman安装的 jupyter notebook在 PATH 变量中搜索 python 二进制文件,而不是在虚拟环境指定的路径中。由于我在主目录中本地安装了 Python 3.7,因此 Jupyter 找不到它,它可能默认为默认的 Python 版本。
所以可能的解决方案是:
Run Code Online (Sandbox Code Playgroud)> wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz > tar -xvf Python-3.7.4.tgz > cd Python-3.5.1/ > ./configure --prefix=$HOME/Python37 > make > make install > virtualenv -p ~/Python3.7/bin/python3 py37 > source py37/bin/activate (py37) > pip install notebook (py37) > python -m notebook
> python> python3> python3.7Run Code Online (Sandbox Code Playgroud)> wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz > tar -xvf Python-3.7.4.tgz > cd Python-3.5.1/ > ./configure > make > sudo make install > virtualenv -p $(which python3.7) py37 > source py37/bin/activate (py37) > ipython kernel install --user --name py37 --display-name "Python 3.7" (py37) > jupyter notebook
Run Code Online (Sandbox Code Playgroud)> wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz > tar -xvf Python-3.7.4.tgz > cd Python-3.5.1/ > ./configure --prefix=$HOME/Python37 > make > make install > export PATH="$HOME/Python37/bin:$PATH" > virtualenv -p py37 > source py37/bin/activate (py37) > ipython kernel install --user --name py37 --display-name "Python 3.7" (py37) > jupyter notebook
| 归档时间: |
|
| 查看次数: |
5462 次 |
| 最近记录: |