我一直在尝试在更改 ipywidget 后自动更新变量并运行代码片段。
到目前为止,我找到的唯一部分解决方案是声明一个全局变量,类似于 github 上的示例(此处):
import ipywidgets as widgets
from IPython.display import display
x = 5
slider = widgets.IntSlider()
slider.value = x
def on_change(v):
global x
x = v['new']
slider.observe(on_change, names='value')
display(slider)
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想要实现的是在更改小部件后自动更改 x 值,而不使用全局变量,并且还更改一些先前定义的变量。它会是这样的:
x = 5
y = []
slider = widgets.IntSlider()
slider.value = x
def on_change(v):
x = v['new']
y.append(x)
slider.observe(on_change, names='value')
display(slider)
Run Code Online (Sandbox Code Playgroud) 我开始更多地使用 Jupyter 笔记本,并且真的开始喜欢它。但是,我发现很难在我的特定设置中使用它。
我有一个工作站来运行所有笔记本电脑,但一天中的大部分时间我都在使用空间有限且没有电源插座的笔记本电脑。我希望能够编辑(但不能运行)这些笔记本,而无需安装和运行完整的 Jupyter 服务器后端,我认为这会消耗大量电量。
我的问题是:我是否可以在不运行 Jupyter 服务器的情况下编辑(而不是运行)笔记本?
我的系统上有 Python 3.7 和 3.8。
我已在 jupyter 笔记本的 3.7 和 3.8 上运行 pip install,但是在尝试创建新笔记本时,内核列表仅显示“Python 3”的一个值
如何让 Python 3.7 和 3.8 都显示在此处?
如何让 ipython 在 emacs 下正常工作?
按照ipython 文档的建议,我启用了 ipython:
(require 'python)
(setq python-shell-interpreter "ipython")
Run Code Online (Sandbox Code Playgroud)
当我启动 ipython 服务器时收到以下警告。
Python 3.7.4 (default, Jul 9 2019, 18:15:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.
WARNING: your terminal doesn't support cursor position requests (CPR).
Run Code Online (Sandbox Code Playgroud)
“ [In]”提示根本不打印。并且当代码从另一个缓冲区发送时(例如通过python-shell-send-buffer)。这是一个示例屏幕转储(我猜测是i 8 i 8来自未正确显示的提示):
WARNING: your terminal doesn't support cursor position requests (CPR).
i
8
i
8
hello world
Run Code Online (Sandbox Code Playgroud)
交互时,“ [Out] …
我正在使用 IntelliJ IDEA Community 2020.1,并且刚刚通过将我使用的环境的 python 版本分配为项目 SDK 来启动一个新项目。
该环境包括以下(相关)包:
另外,在 IntelliJ 中,我安装了 Python Community Edition 插件。但是,当我想在 IntelliJ 中编辑“.ipynb”文件时,我看不到像普通 Jupyter 笔记本一样在单元格中拆分的代码。
我已经仔细检查了所有内容,我认为我没有错过这里建议的任何内容: https: //www.jetbrains.com/help/idea/jupyter-notebook-support.html,但我无法解决问题。
这个问题以前曾被问过,但没有一个答案是令人不满意的。我正在尝试使用 jupyter 笔记本(ipython)为 pandas 设置一个 PostgreSQL 数据库,但总是出现以下错误ModuleNotFoundError: No module named 'psycopg2' 与我连接到我的 Django 项目一样,它工作正常。
为此,即使我面临同样的问题,我也安装了以下软件包。我使用的是 ubuntu 18.04 仿生版本。
sudo apt-get install python3-psycopg2
pip3 install psycopg2-binary
Run Code Online (Sandbox Code Playgroud)
运行我的 jupyter 笔记本时,ipython 内核(Python 3.8、Anaconda)不断死机并重新启动。
我想找出是什么原因导致它行为不当。遗憾的是,除了内核已死并重新启动之外,我找不到任何调试信息。
如何找到可能有助于事后分析的更详细信息?有没有错误日志之类的?
我试过
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:60% !important; }</style>"))
Run Code Online (Sandbox Code Playgroud)
从这个答案来看。我也尝试过
%%html
<style>.container { width:60% !important; }</style>
Run Code Online (Sandbox Code Playgroud)
但它们不起作用。
当我跑步时:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
Run Code Online (Sandbox Code Playgroud)
我有
/var/folders/6g/6gqq4lhx4jbcl4_tbrsxj3xr0000gq/T/ipykernel_5625/333572366.py:1: DeprecationWarning: 自 IPython 7.14 起不推荐从 IPython.core.display 导入显示,请从 IPython 显示导入
from IPython.core.display import display, HTML
我在IPython中运行命令
cd $cs<TAB>
Run Code Online (Sandbox Code Playgroud)
但它不允许我扩展路径.
如何让IPython读取shell变量?
ipython ×10
python ×5
python-3.x ×2
css ×1
debugging ×1
display ×1
emacs ×1
html ×1
ipywidgets ×1
jupyter ×1
jupyter-lab ×1
pandas ×1
postgresql ×1
psycopg2 ×1