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

查看:123
本文介绍了更改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

usr\bin\python3

,我可以导入我用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

usr\bin\python

以及我随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,它通常被称为安装kernelspec".在您的情况下,您需要:

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:

  • 如果不确定,可以始终用/full/path/to/python安全地替换python.
  • 使用pip时,您始终可以将pip(或pip3)替换为/full/path/to/python -m pip以使用链接到所需python的点子.
  • 如果您想使用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天全站免登陆