简体   繁体   English

为什么我的Jupyter(Ubuntu)中的每一行的代码颜色都不同?

[英]Why are the code colours different for every line in my Jupyter (Ubuntu)?

I was using Jupyter in Windows and just switched to Ubuntu. 我在Windows中使用Jupyter,刚刚切换到Ubuntu。 I found the colour of the code is very weird in the firefox browser. 我在firefox浏览器中发现代码的颜色很奇怪。 Eg it highlights the variables in every other line. 例如,它突出显示每个其他行中的变量。

I tried to solve this problem by installing a custom theme and the effect should be like 我试图通过安装自定义主题来解决这个问题,效果应该是这样的

在此输入图像描述

Instead, it still highlights every other variable on my side, like 相反,它仍然突出了我身边的所有其他变量,比如

在此输入图像描述

This just makes my eyes very tired when try to debug the code. 这只会让我的眼睛在尝试调试代码时非常疲惫。

I also tried disabling all the add-ons in Firefox which didn't help. 我也尝试禁用Firefox中的所有附加组件,但没有帮助。 Is there any setting that I can change to restore to the default colour display? 是否有任何设置可以更改为恢复默认颜色显示?

I sometimes get this if I'm copying/pasting from a source that has a different indentation size than that of the jupyter notebook. 如果我从具有与jupyter笔记本不同的缩进大小的源复制/粘贴,我有时会得到这个。 In your screenshot it looks like a small indent size so this seems like the likely culprit. 在你的截图中,它看起来像一个小的缩进大小,所以这似乎是可能的罪魁祸首。 Try highlighting the full block of indented code and hitting ctrl+[ then ctrl+] (this unindents the selected lines of code, then reindents them using the jupyter indent size). 尝试突出显示缩进代码的完整块并按下ctrl+[然后按ctrl+] (这取消了所选的代码行,然后使用jupyter缩进大小重新使用它们)。

If this doesn't work, you might try checking to see if there are any custom indentation settings specified in either ".jupyter/nbconfig/notebook.json" or ".jupyter/custom/custom.js" (... or whatever the Windows equivalents are). 如果这不起作用,您可以尝试检查是否在“.jupyter / nbconfig / notebook.json”或“.jupyter / custom / custom.js”中指定了任何自定义缩进设置(...或者其他Windows等价物是)。

In ".jupyter/nbconfig/notebook.json", I have the indentUnit set to 4 spaces (and have also enabled linewrapping). 在“.jupyter / nbconfig / notebook.json”中,我将indentUnit设置为4个空格(并且还启用了行换行)。

{
  "CodeCell": {
    "cm_config": {
      "indentUnit": 4,
      "lineWrapping":true
    }
  }
}

Most editors allow you to set your indent size (Atom, sublime text, etc.) so you can avoid this issue in the future by making sure you have the same indent size everywhere you're swapping code to/from (assuming this is what's causing the red highlighting). 大多数编辑器允许您设置缩进大小(Atom,崇高文本等),以便您可以确保在将代码交换到/来自的任何地方都具有相同的缩进大小,以避免此问题(假设这是什么的)导致红色突出显示)。 Python's default is 4 so def recommend sticking with that. Python的默认值是4所以def建议坚持使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的代码的输出在每一行中都是不同的字母 - The output of my code comes as a different alphabet in every line 为什么我的 jupyter kernel 在 vs code jupyter 扩展中不可见? - Why my jupyter kernel is not visible in vs code jupyter extension? 我的图例颜色与我的图形线条颜色不匹配? - My figure legend colours do not match my graph line colours? 为什么我的 for 循环打印每隔一行而不是每一行? - Why is my for-loop printing on every other line and not every line? 为什么每次我在 python 中运行我的代码时都会打印附加行? - why appended line is being printed every time i run my code in python? 为什么我的代码在 windows 中运行良好,但在 ubuntu 中运行不正常 - Why my code work well in windows, but not in ubuntu 为什么我的 python 代码中的每一行后面都有空格? - Why am I getting spaces after every line in my python code? 为什么词云的 output 在 jupyter notebook 和我的 flask 应用程序中不同? - why output of word cloud is different in jupyter notebook and my flask app? 为什么我的代码没有检查列表中的每个值? - Why is my code not checking every value in list? 为什么我在 Jupyter 上的代码不生成 output - Why doesn't my code on Jupyter produce an output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM