I have a very simple code here
import torch
l = torch.nn.Linear(2,5)
v = torch.FloatTensor([1, 2])
print(l(v))
under torch.FloatTensor, pylint in visual studio code claims that 'Module torch has no 'FloatTensor' member pylint(no-member).
However, the code works fine. Is this a false positive? How can I disable pylint for this specific instance?
Press: CTRL + Shift + P
Click on "Preferences: Open Settings (JSON)"
Add this line into JSON :
"python.linting.pylintArgs": ["--generated-members", "from_json,query"]
What worked for me was noticing what modules were giving those errors, which is torch for you, and then followed these steps:
hit CTRL + Shift + P
click on "Preferences: Open Settings (JSON)"
add the following to the JSON file you are presented with:
"python.linting.pylintArgs": [
"--generated-members", "torch.*"
]
for the sake of this answer, say that there were other modules giving problems, then you'd write:
"python.linting.pylintArgs": [
"--generated-members", "torch.* other_module.* next_module.*"
]
Yes it is a problem of Pylint
If you use Anaconda, you can do:
1. search python.linting.pylintPath in your VSCode setting
2. change it to (You Anaconda Path)\pkgs\pylint-1.8.4-py36_0\Scripts\pylint
You Anaconda Path and pylint-1.8.4-py36_0 may vary
A better answer to this question here: Why does it say that module pygame has no init member?
The answer above marked as the answer with references to Anaconda doesn't make sense to me, probably a newbie issue.
Please follow the link to get the real scoop, but to summarize -
Replacing extensionname with your problem module name, such as pygame or RPi or Torch:
Hit CTRL + Shift + P
Click on "Preferences: Open Settings (JSON)"
Add the following to the JSON file you are presented with (inside the {}, if there are entries already there add leading comma as well):
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=extensionname" // comma separated
]
As Tomari says, it does work on windows.There is a little difference on linux. The path maybe like "(You Anaconda Path)/pkgs/pylint-2.6.0-py38_0/bin/pylint".
Related
How can I move a line (or set of selected lines) down or up in jupyter notebook. Are there any shortcuts?
After moving line 3 one line up:
For example ALT+UP or ALT+DOWN is for up/down displacement that is used in Eclipse IDE.
This question discusses cell displacement.
TLDR:
By following this tutorial, I was able to enable all the sublime-text shortcuts (which includes the moving lines with Ctrl+Up/Ctrl/Down).
I then was able to furthermore, customize the shortcuts by editing the sublime.js
Complete answer:
Find your jupyter path with jupyter --config-dir
Add the following code to <JUPYTER-PATH>/custom/custom.js:
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
// setTimeout(function(){ // uncomment line to fake race-condition
cell.Cell.options_default.cm_config.keyMap = 'sublime';
var cells = IPython.notebook.get_cells();
for(var cl=0; cl< cells.length ; cl++){
cells[cl].code_mirror.setOption('keyMap', 'sublime');
}
// }, 1000)// uncomment line to fake race condition
}
);
You need to find this codemirror/keymap/sublime.js (that is required in the code from point 2), for me, it was in <MY-PYTHON-ENVIRONMENT>/lib/python3.8/site-packages/notebook/static/components/codemirror/keymap/sublime.js
At the end of this file, you can edit the shortcuts, in the keyMap.pcSublime section of this file (if you have a PC).
For OP, the lines to edit would be: swapLineUp and swapLineDown
I did this with Ubuntu & sublime installed.
You can select the line with mouse in jupyter notebook. Drag it
up or down before the line where you want to move it. Press >
button on keyboard while your text is still selected.
This will bring the cursor to end of selected line,
but before the text of line being replaced. Press Enter.
Since jupyter works with code blocks you can use that shortcut between code blocks as
Ctrl + Shift + -
But this will only works between code cells not in the same code block. I don't think there is a built-in shortcut for that. For more shortcuts you can look here: https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/
There's no such a shortcut in Jupyter, however, you can manage your own shorcuts Go to Help > Edit keyboard Shortcuts and start setting your commands.
There's some good info on this other post which will lead you to manage your profile's notebook.json file and so on.
Hope this was useful ;)
Edit: typo
You can create your custom shortcuts in Jupyter notebook
Jupyter Shortcuts
I just installed jedi auto-completion from sublimetext 3 in python because I wanted to make code write easier.
after everythings done.. when i write string. and all the statements and class names pops up. great
but problem comes here:
after i type print and type(
automatically print(sep=..., end=..., file=..., flush=...) pops up..
i don't want this big line.. i just want to print "()"
what should i do?
i use ubuntu 18, python version 3.7.2
Go to the sublime text editor.
preference > browse packages
And then click on it and it will take you to the file manager (Where the packages are save for sublime).
Now there find JD - Python Autocompletion
then head to JD-Python Autocompletion > sublime_jd > utils.py
Now you have to edit this file...
In this file around line number 34, you will find a line mentioned below (Use find to find this line)
complete_funcargs = get_settings_param(
view, 'auto_complete_function_params', 'all')
Now just remove all. Like below:-
complete_funcargs = get_settings_param(
view, 'auto_complete_function_params', '')
That's all, Now restart the sublime and enjoy
I just started learning python in order to do some stuff for the company I work for. I want to add a command line option like -doc but Ì somehow struggle with adding color or any other custom text format to my documentation (to be printed in cmd).
I have following problems:
1. Ansi escaping doesn't work as I expect when reading tutorials on the internet:
This code: print('\033[31m' + 'Hello' + '\033[0m') doesn't escape at all so I end up with this output: [31mHello[0m
2. I can't import colorama because my users have a plain python installation and I can't just add libraries to it. So my plan would be to add colorama to my project structure.
To 1: Do I misunderstand something important or has someone an idea what I`m doing wrong?
To 2: Is there a way to install colarama into my project without any changes to the plain python installation or dependencies to the outside of my project?
... I would accept any other solution to my problem.
Just use batch to do that.
Code:
#echo [31mHello[0m
I installed Pathogen
and followed http://rkulla.github.io/pydiction/ for installing pydiction
Configuration in my /root/.vimrc also I changed in the path which is given by :echo $MYVIMRC
My .vimrc file :-
filetype plugin on
let g:pydiction_location = '/root/.vim/bundle/pydiction/complete-dict'
let g:pydiction_menu_height = 3
But after these all instructions also I am not getting any suggessions ( by giving tab key) from complete-dict
If anything I left to configure please help me
when I am pressing C-N also in my vim file it is showing like this :-
-- Keyword completion (^N^P) Pattern not found
I'm trying to find a way for mathjax to not use STIX fonts for math in my iPython notebook. Instead, I'd much rather have it use the 'TeX' fonts. According to the documentation for Mathjax I should use:
MathJax.Hub.Config({
"HTML-CSS": {
preferredFont: "TeX"
}
});
That being said, I'm not sure where to put this. I've already tried putting this chunk of code into my custom.js file pertaining to my own ipython profile, but it doesn't work. Ideally, I'd like to make ipython profile specific adjustments for mathjax.
I recently had the exact problem. I really don't like the default STIX-Web font to render equation. After experimenting for a little while, I found a way to change the MathJax font in Jupyter Notebook. My Jupyter Notebook version is 4.3.1 and it is shipped with Anaconda. I assume the solutions for other versions should be similar.
I tried to edit custom.js both in /notebook/static/custom/custom.js and ~/.jupyter/custom/custom.js. Doesn't work. I also tried to edit mathjaxutils.js. It does nothing. Finaly I saw this post https://github.com/jupyter/help/issues/109. I realize Jupyter uses main.min.js to read MathJax configuration. So here is the solutions:
Download MathJax(https://github.com/mathjax/MathJax) from Github.
Unzip the MathJax file and go into the folder
copy jax/output/HTML-CSS/fonts/TeX into directoy ../notebook/static/components/MathJax/jax/output/HTML-CSS/fonts/
copy fonts/HTML-CSS/TeX into ../notebook/static/components/MathJax/fonts/HTML-CSS/
open ../notebook/static/notebook/js/main.min.js, search for availableFonts. It should be around line 14894. Change it to
...
availableFonts: ["STIX-Web","TeX"],
imageFont: null;
preferredFont: "TeX",
webFont: "TeX"
...
Refresh the notebook.
Jupyter ships with its own (smaller) version of MathJax. This is why it is not able to find the (Computer Modern) 'TeX' font -- there only is the STIX font.
To fix this, I was able to do the following:
Download MathJax 2.7 and copy the jax directory.
Replace Jupyter's jax directory with the copied one:
For the default environment: ~/anaconda3/lib/python3.7/site-packages/notebook/static/components/MathJax/jax
For a different environment: ~/anaconda3/envs/<ENVIRONMENT>/lib/python3.7/site-packages/notebook/static/components/MathJax/jax
Restart Jupyter, right-click on a piece of math and switch the 'Math Renderer' to SVG.
(Adjust python version in path if yours is not 3.7; If you are using miniconda the path should be ~/opt/miniconda3/lib/...)
A simple test to make sure that you're getting the configuration correct is to change preferredFont: "TeX" to scale: 200. Then save and reload a notebook. The math should be obviously way bigger than before. So assuming that worked, it means your config.js is doing what it needs to.
Now, more to the point, try adding another line so that your configuration looks like
MathJax.Hub.Config({
"HTML-CSS": {
availableFonts: ["TeX"],
preferredFont: "TeX",
}
});
Don't forget to fully refresh the notebook page after you've saved that. This overrides (what I'm guessing is) the default value of that availableFonts variable, which would allow STIX if mathjax can't find TeX. I'm not sure why it seems to ignore the preferred font, but this seems more like a mathjax issue than an ipython issue.
So now, if it still isn't in TeX font (which mathjax seems to call MathJax_Math-Italic.otf, or similar), I would guess that mathjax just can't find that font, and may have fallen back on something else. If that is the case, there's something messed up about your mathjax installation.
Take a look at some of the numericalmooc lessons such as this one where the MathJax configuration is included through a css file which is imported at some point in the notebook.
I've tweaked #Stefan Shi's answer to something a little easier, at least if you have the command-line svn installed.
Put the following into a script file called install_tex_fonts (install_tex_fonts.bat in Windows-land):
svn export https://github.com/mathjax/MathJax/trunk/fonts/HTML-CSS/TeX/woff fonts/HTML-CSS/TeX/woff
svn export https://github.com/mathjax/MathJax/trunk/jax/output/HTML-CSS/fonts/TeX jax/output/HTML-CSS/fonts/TeX
Move the script file into {PYTHON}/Lib/site-packages/notebook/static/components/MathJax where {PYTHON} is the root directory where you installed Python
Open a shell (command prompt) in this directory
Run the script by typing install_tex_fonts (or ./install_tex_fonts on *nix systems; I guess you also have to chmod a+x it)
Add the following section in your ~/.jupyter/custom/custom.js file (the $([IPython.events]).on('app_initialized.NotebookApp') line should already be there):
$([IPython.events]).on('app_initialized.NotebookApp', function(){
MathJax.Hub.Config({
"HTML-CSS": {
availableFonts: ["TeX"],
preferredFont: "TeX",
webFont: "TeX"
}
});
Following #Ian's information, you can get your initial HTML-CSS MathJax configuration from python with the below code (demjson is a soft requirement which allows us to partially process json in a javascript file: pip install demjson):
import sys
from pathlib import Path
MathJax_cfg_pth = (
Path(sys.executable).parents[0] /
# below path may differ
'Lib/site-packages/notebook/static/components/MathJax/jax/output/HTML-CSS/config.js'
)
with open(MathJax_cfg_pth, 'r') as f:
MathJax_cfg = f.read()
import demjson
start_cfg = MathJax_cfg.find("config:{") + 7
open_braces = 0
for i, c in enumerate(MathJax_cfg[start_cfg:]):
if c == '{':
open_braces += 1
elif c == '}':
if open_braces == 0:
break
open_braces -= 1
initial_configuration = demjson.decode(
MathJax_cfg[
start_cfg : start_cfg + i
].replace("(", "'(").replace(")", ")'")
)
Having this will be helpful if you want to revert any changes without restarting your notebook kernel. For the curious, my initial_configuration is here: https://pastebin.com/JkatcrAC
Next we can update a HTML-CSS MathJax setting in our current runtime by displaying HTML containing a short script. If you wanted to update the size of HTML-CSS displays you could use the following function:
from IPython.core.display import HTML
MathJax_scale_script = """
<script>
MathJax.Hub.Config({
"HTML-CSS": {
scale: %s
}
});
</script>
"""
def update_Math_size(size):
# 100 is default
display(HTML(MathJax_scale_script%size))
For example, update_Math_size(200) for double the size, and update_Math_size(100) to revert back to my default setting.