更改 Python 可执行文件 [英] Changing Python Executable

查看:64
本文介绍了更改 Python 可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程还很陌生,对在 UNIX 环境中这样做也很陌生,所以请耐心等待.

I'm pretty new to programming, and very new to doing so in a UNIX environment, so please bear with me.

当我跑步时

import sys
sys.executable

在我的 Python 3 控制台中,输出是

in my Python 3 console, the output is

usrinpython3

而且我可以导入我用 pip3 安装的任何库,没问题.当我在运行 Python 3 内核的 Jupyter Notebook 中执行此操作时,输出为

and I'm able to import whatever libraries I've installed with pip3, no problem. When I do so in my Jupyter Notebook running a Python 3 kernel, the output is

usrinpython

我无法访问我用 pip3 安装的库.我该怎么做才能修复它,以便 Jupyter 从正确的位置执行 Python,以便我可以使用我为 Python 3 安装的任何东西和 pip3?

and the libraries that I've installed with pip3 are inaccessible to me. What can I do to fix it so Jupyter is executing Python from the right place so I can use anything I've installed for Python 3 with pip3?

谢谢!

推荐答案

简短

您需要向 Jupyter 注册您的 Python 内核,因为它找到正确的"Python

You need to register your Python kernel with Jupyter, for it to find the "right" Python

Jupyter 旨在处理多种内核和语言;一些用户拥有数十个内核是很常见的,许多内核可以是相同的语言,只有很小的差异.您通常需要告诉"jupyter 有关这些内核的信息,这通常称为安装内核规范".在您的情况下,您需要:

Jupyter is meant to work with multiple kernels, and languages; it is common for some users to have tens of kernels, many can be the same language, with small differences. You usually need to "tell" jupyter about these kernels, it is often referred to as "Installing a kernelspec". In your case you need to:

  • 安装 IPython &用于 Python 3 的 ipykernel
  • 使用您刚刚安装的 ipykernel:安装 kernelspec.

您会在上面的链接中找到说明,但有一些提示:

You'll find instruction on above link, a few tip though:

  • 如果您不确定,您始终可以安全地将 python 替换为 /full/path/to/python.
  • 当使用pip时,你总是可以用/full/path/to/python替换pip(或pip3) -m pip 使用链接到你想要的python的pip.
  • 如果您想使用 sudo,请不要.人们告诉你使用 sudo 会在几个月后当他们的 Linux 发行版需要更新时遇到问题——除非你真的知道你在做什么.
  • You can always safely replace python by /full/path/to/python if you are unsure.
  • when using pip, you can always replace pip (or pip3) by /full/path/to/python -m pip to use the pip linked to the python you want.
  • If you are tempted to use sudo, don't. People telling you to use sudo get issues after a few month when their linux distribution need to be updated – unless you really know what you're doing.

使用 Jupyter 注册 Python 内核后,它应该会出现在菜单中.不过,您可能需要刷新浏览器.

Once you've registered the Python kernel with Jupyter, it should just appear in the menus. You may need to refresh your browser though.

享受吧!

这篇关于更改 Python 可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆