How to stop Jupyter Notebook from turning urls into active links? - python

I recently updated from iPython Notebook 3.x to Jupyter Notebook 4.x and it seems that they changed how urls are handled in code cells.
Screenshot of how it works now
Previously, any url within quotes would be treated like any other string. It was marked up in red font and could be edited at will (3rd line in the image). This is how I want it to work again.
Unfortunately, now whenever you have a url (1st line) and you put quotes around it (2nd line) it turns it into an active link for the website. This is infuriating because I can no longer allow me to edit the url because it is being treated as an interact-able object. It even prevents me from modifying the rest of the line of code that the url is a part of. I can't even move the cursor into the line. The cursor just vanishes. To workaround this 'feature' I have to cut and paste the line of code into notepad, edit it, then re-paste it back into the notebook.
I use Google Chrome as my web browser for the notebooks, which is one of the supported browsers according to the website. Could it be that there is a setting in Chrome which is messing things up? Or is it that there is a setting in the Jupyter notebook that I can change to revert the behavior? Or am I just going to have to downgrade to iPython 3.x?

Related

output text in jupyter notebook

I'm working with vscode in jupyter notebooks and when executing a code the text suddenly looks out of range, before it looked normal, I tried reinstalling vscode.
This is the view I have from the github repository, before it looked like this in vscode:
Before
in vscode suddenly it started to look like this:
After
before they told me that the font is the problem and that I should edit the json of the configuration, however, the json is only with the theme for vscode since I have uninstalled everything related and I have reinstalled it, and it still continues the same
It's related to VSCode, you can wait for the update of VSCode. You can refer to this page for more details.
Your font has changed from fixed width to variable width. This is something you will find in settings.json but should change via VSCode's settings page. Search for "font" and select an appropriate option - perhaps Courier.

Trusting a notebook is not working in PyCharm

I want to run a Jupyter notebook in PyCharm but on cells that are executing javascript, I get the message, that the notebook is not trusted.
When I click the "Trusted" checkbox, the arrow appears for a second and then disappears again. The notebook stays untrusted. Also using the command-line interface for Jupyter with
jupyter trust notebook.ipynb
doesn't work.
When I open the notebook on the browser with the same kernel running, it works just fine.
I also want to add that I have three projects open at the same time. When I just open the project, which is containing the notebook, I can click the "Trusted" checkbox and it will stay checked, but still, the javascript cells will not execute.
Maybe that's a bug, but probably I messed up some settings? Can you help me find out, which settings I can change and if there are other options to get the notebook trusted within the IDE?
Have a nice day!
I had the same problem when I moved the notebook's directory. What solved it for me in PyCharm was to copy and paste the notebook's content into a new file.
I came across this issue when specifying %matplotlib notebook.
Changing this to %matplotlib inline got the plotting to work.
Not fully understanding the issue or how this solves it but it is sufficient for my application.

How to make VS code's jupyter notebook's codetext bold?

I am trying to make code text on jupyter notebook on VS code be bold, but no matter how I tweak the settings.json file I can't seem to find a way to make it happen. As I have noticed, usual python code text in .py files is changing when i change settings.json file but .ipynb file is not reacting. For some reason if I use command palette to change themes jupyter notebook's code is changing color as well but the codetext itself is not becomming bold. Is there a way to solve this?
I'm a developer on the VSCode python extension. Currently our notebook editor is implemented as a webview (basically a way for extensions to put a webpage into VS Code's UI). We've tried to match things up as best as we can, but in this scenario we can't support many VS Code editor settings and features. This setting that you are changing is one of the ones that we don't support.
On the plus side, VS Code core team is currently in the process of adding build in notebook support. When we move over to this the notebook cells will be full real VS Code editor instances and will support this setting. This feature is currently in early preview (expect plenty of change and issues) if you right click on a ipynb file in VS Code Insiders and pick "open in preview Notebook Editor."
At present, the Jupyter notebook function in VSCode is provided by the python extension.
When it is used as markdown, the text output is bold. (use "# %%[markdown]").
But it does not currently support setting its code bold style. We look forward to its further improvement of this setting.

Coursera jupyterNotebook: revert to the beginning

I'm using jupyterNotebook from Coursera but see no way to revert everything to the beginning.
The only option relevant seems to be "Revert to Checkpoint" -- but I didn't save a checkpoint at the beginning.
Does it mean that I am unable to revert to it?
Open your notebook at Coursera
Rename it
After renaming just add ?forceRefresh=true to the end of your notebook URL
Hit enter
You now have old renamed version and new refreshed to default one
The procedure is described here.
As of July 2019 the ?forceRefresh=true solution worked for me.
These steps will work as of April, 2020:
Rename your notebook and add ?forceRefresh=true to the url and press enter. Your entire Jupyter notebook will be restarted. Go to the course week and a fresh notebook will be there.
Better late than never -
This is from the Coursera help section.
To keep your old work and also get a fresh copy of the initial Jupyter Notebook:
Make a copy of your Notebook by clicking File, then Make a copy. We recommend using a naming convention such as “Assignment 1 - Initial” and “Assignment 1 - Copy” to keep your notebook environment organized. You can also download this file locally.
Click Control Panel, then choose My Server
Find the name of your previous file, as well as the new copy of your file.
Delete the original notebook file (not the copy) by selecting the checkbox next to the filename. Click the trashcan icon that appears to delete the file.
Click Control Panel, then choose Stop My Server.
Select My Server to restart.
After a few minutes, launch the notebook again from your Course Home. If you get a 404 error while the notebook server restarts, wait a few minutes and try again.
After the restart is complete, you will see a fresh copy.
I believe this is a new feature in Coursera
This is the instruction from a course I was taking:
In any Jupyter notebook, first save your work by going clicking File -> Download as -> Notebook (.ipynb)
Next, click File -> Open. This opens up the file directory.
Select the notebook you wish to refresh from the list by clicking the check box next the the filename
Click the trashcan icon at the top to delete the notebook
Copy this text: ?forceRefresh=true and paste it onto the end of the URL in your browser bar then hit .
You will see your workspace refresh with the updated copy of the notebook
These steps:
1. Open your notebook at Coursera
2. Rename it
3. After renaming just add `?forceRefresh=true` to the end of your notebook URL
4. Hit enter
5. You now have old renamed version and new refreshed to default one
Still work as of 05/14/2021

Sublime Text plugin can’t find my default browser

TL;DR: Sublime Text gets a different response from webbrowser._browsers than my terminal.
This has been driving me nuts. I use a plugin, GitLink which will open a GitHub link from your current file. It relies on Python’s webbrowser tool to open the url. The problem is my default browser is Chrome, but it keeps opening Firefox.
In my terminal, if I launch into python or python3, webbrowser.open_new_tab('https://stackoverflow.com') will correctly launch in Chrome. webbrowser._browsers will correctly list 'chrome' as one of my browsers.
However, in the Sublime Text console, webbrowser._browsers is missing Chrome. It lists all the other browser save for the one I actually want. What gives? How is Sublime Text getting a different list than when I run python in my terminal? How do I get it to match?
There are several things you could try.
1. Set the BROWSER environment variable:
As Keith Hall implied this problem might be solved by setting your BROWSER environment variable. If you don't know how look it up for your version - OSX changed how environment variables get set at some point so there are different ways of doing this for different versions of OSX. However, I am on Linux, and my BROWSER environment variable is not set and ST always opens urls in my default browser, this includes calls to webbrowser.open_new_tab() which (as I assume you saw) is what GitLink uses to open urls, so this may not solve the problem.
2. Modify GitLink (your installed version):
First test if this will work - works fine on Linux.
Copy and paste the following 2 lines into the ST console:
import webbrowser
webbrowser.get("chrome").open_new_tab("http://www.google.com")
If that does not open Chrome with Google.com try:
# google-chrome: Chrome variant.
webbrowser.get("google-chrome").open_new_tab("http://www.google.com")
# macosx: uses the OSX default browser.
webbrowser.get("macosx").open_new_tab("http://www.google.com")
# links: generic; doubtful but worth trying at this stage.
webbrowser.get("links").open_new_tab("http://www.google.com")
The full list of possible values may be helpful.
Another possibility is to use the full path instead, see this StackOverflow answer or try:
# Replace path with your path to Chrome if necessary.
webbrowser.register('chrome_path', None, webbrowser.BackgroundBrowser("/Applications/Google Chrome.app"))
webbrowser.get('chrome_path').open_new_tab(url)
Once that is working:
Install the PackageResourceViewer plugin; after it is installed...
Open the Command Palette and select: PackageResourceViewer: Open Resource
In the list of packages select: GitLink
In the list of files select: GitLink.py
The file GitLink.py will open...
If you save this file (nothing will happen at all if you close it without saving) then a copy of GitLink.py will get saved on your system in this location: ST_CONFIG/Packages/GitLink/GitLink.py - this version of the file will override the version of GitLink.py which is stored in the Gitlink.sublime-package file which Package Control would have installed in the Installed Packages folder. Even if the GitLink package gets updated the version in the .sublime-package file will still get overridden. Not a problem, all you need to do to get rid of the changes made is to delete the folder ST_CONFIG/Packages/GitLink/ which contains the GitLink.py file and ST will start using the version from the .sublime-package file again.
The modification is easy:
Scroll down to the bottom of GitLink.py where you will see the lines:
if(args['web']):
webbrowser.open_new_tab(url)
Just change the webbrowser.open_new_tab(url) line to the following (replacing "chrome" if necessary with the value which worked in the console):
if(args['web']):
webbrowser.get("chrome").open_new_tab(url)
Save the file, the plugin should be updated immediately by ST (check the console for the "reloading plugin" message to be sure if you want). The plugin should now open your urls in Chrome.
3. Open an issue on GitLink's GitHub page:
The issue page is here. State your problem and request a setting be added so that users can specify which browser Python's webbrowser module should use.
I suggest you do this anyway and add a link to this StackOverflow page to your issue for reference.

Categories