Popular New Releases in Jupyter
dash
Dash v2.3.1
ipython
See https://pypi.org/project/ipython/
jupyterlab
v3.4.0a0
plotly.py
v5.7.0
notebook
v7.0.0a2
Popular Libraries in Jupyter
by jakevdp jupyter notebook
32215 NOASSERTION
Python Data Science Handbook: full text in Jupyter Notebooks
by ageron jupyter notebook
23897 Apache-2.0
A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in python using Scikit-Learn and TensorFlow.
by ageron jupyter notebook
16775 Apache-2.0
A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
by plotly python
16243 MIT
Analytical Web Apps for Python, R, Julia, and Jupyter. No JavaScript Required.
by bokeh python
16149 BSD-3-Clause
Interactive Data Visualization in the browser, from Python
by wesm jupyter notebook
15489 NOASSERTION
Materials and IPython notebooks for "Python for Data Analysis" by Wes McKinney, published by O'Reilly Media
by ipython python
15262 NOASSERTION
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
by fchollet jupyter notebook
13453 MIT
Jupyter notebooks for the code samples of the book "Deep Learning with Python"
by jupyter python
12379 BSD-3-Clause
Jupyter metapackage for installation, docs and chat
Trending New libraries in Jupyter
by lux-org python
3417 Apache-2.0
Automatically visualize your pandas dataframe via a single print! 📊 💡
by orchest python
2877 AGPL-3.0
Build data pipelines, the easy way 🛠️
by jupyterlite python
1957 BSD-3-Clause
Wasm powered Jupyter running in the browser 💡
by dotnet csharp
1657 MIT
.NET Interactive takes the power of .NET and embeds it into your interactive experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
by abhishekkrthakur python
1486 MIT
Run VSCode (codeserver) on Google Colab or Kaggle Notebooks
by abhi1thakur python
1324 MIT
Run VSCode (codeserver) on Google Colab or Kaggle Notebooks
by jupyter-naas jupyter notebook
1130 BSD-3-Clause
Ready to use data science templates, organized by tools to jumpstart your projects in minutes. 😎 published by the Naas community.
by giswqs jupyter notebook
913 MIT
A collection of 360+ Jupyter Python notebook examples for using Google Earth Engine with interactive mapping
by gzuidhof typescript
831 MPL-2.0
In-browser literate notebooks
Top Authors in Jupyter
1
38 Libraries
38607
2
37 Libraries
19769
3
35 Libraries
13622
4
27 Libraries
31760
5
22 Libraries
496
6
20 Libraries
942
7
19 Libraries
405
8
18 Libraries
1849
9
18 Libraries
1699
10
17 Libraries
822
1
38 Libraries
38607
2
37 Libraries
19769
3
35 Libraries
13622
4
27 Libraries
31760
5
22 Libraries
496
6
20 Libraries
942
7
19 Libraries
405
8
18 Libraries
1849
9
18 Libraries
1699
10
17 Libraries
822
Trending Kits in Jupyter
No Trending Kits are available at this moment for Jupyter
Trending Discussions on Jupyter
Compute class weight function issue in 'sklearn' library when used in 'Keras' classification (Python 3.8, only in VS code)
How to Export Jupyter Notebook by VSCode in PDF format? (Windows 10)
How to undo/redo changes inside the selected cell in Jupyter notebook?
iPyKernel throwing "TypeError: object NoneType can't be used in 'await' expression"
"Attempting to perform BLAS operation using StreamExecutor without BLAS support" error occurs
Running cells with Python 3.10 requires ipykernel installed
ipykernel (Jupyter notebook/labs) cannot import name ''filefind" from traitlets.utils
lfortran in a jupyter notebook kills kernel
Pandas - How to Save A Styled Dataframe to Image
embedding jupyter notebook/ google colab in Django app
QUESTION
Compute class weight function issue in 'sklearn' library when used in 'Keras' classification (Python 3.8, only in VS code)
Asked 2022-Mar-27 at 23:14The classifier script I wrote is working fine and recently added weight balancing to the fitting. Since I added the weight estimate function using 'sklearn' library I get the following error :
1compute_class_weight() takes 1 positional argument but 3 were given
2
This error does not make sense per documentation. The script should have three inputs but not sure why it says expecting only one variable. Full error and code information is shown below. Apparently, this is failing only in VS code. I tested in the Jupyter notebook and working fine. So it seems an issue with VS code compiler. Any one notice? ( I am using Python 3.8 with other latest other libraries)
1compute_class_weight() takes 1 positional argument but 3 were given
2from sklearn.utils import compute_class_weight
3
4train_classes = train_generator.classes
5
6class_weights = compute_class_weight(
7 "balanced",
8 np.unique(train_classes),
9 train_classes
10 )
11class_weights = dict(zip(np.unique(train_classes), class_weights)),
12class_weights
13
ANSWER
Answered 2022-Mar-27 at 23:14After spending a lot of time, this is how I fixed it. I still don't know why but when the code is modified as follows, it works fine. I got the idea after seeing this solution for a similar but slightly different issue.
1compute_class_weight() takes 1 positional argument but 3 were given
2from sklearn.utils import compute_class_weight
3
4train_classes = train_generator.classes
5
6class_weights = compute_class_weight(
7 "balanced",
8 np.unique(train_classes),
9 train_classes
10 )
11class_weights = dict(zip(np.unique(train_classes), class_weights)),
12class_weights
13class_weights = compute_class_weight(
14 class_weight = "balanced",
15 classes = np.unique(train_classes),
16 y = train_classes
17 )
18class_weights = dict(zip(np.unique(train_classes), class_weights))
19class_weights
20
QUESTION
How to Export Jupyter Notebook by VSCode in PDF format? (Windows 10)
Asked 2022-Mar-07 at 15:10When I try to export my Jupyter Notebook in pdf format in VSCode like this:
and jupyter output panel says:
so i tried to install MikTeX and update the required packages, but still I can't export Jupyter Notebooks in PDF format by VSCode!
how can I fix this problem?
Note That I know i can do it by convert it to HTML and then with ctrl+p
try to save it as pdf! but I want to convert it to pdf in straight way!
ANSWER
Answered 2021-Sep-03 at 21:20You can try following URL. Hope it will solve your issue
https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_export-your-jupyter-notebook
I just tried in Linux(Ubuntu 20.04) and it worked for me
You can follow this steps:
sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-latex-recommended
- Active env where you have jupyter installed
- Execute this command:
jupyter nbconvert --to pdf your_file.ipynb
QUESTION
How to undo/redo changes inside the selected cell in Jupyter notebook?
Asked 2022-Feb-22 at 14:01I am using Jupyter notebook (from anaconda Jupyter lab) on Windows 10 and tried to undo/redo changes in the selected cell. However, I can only undo/redo changes in the whole notebook.
For example, I edited cell#1 then cell#2. Say I want to undo changes in cell#1, so I go to cell#1 and press control+z, it will however undo the change in cell#2.
My friend using Mac doesn't have this issue. Are there any settings for this? I searched online and didn't find anyone who has the same problem. It is so weird!
ANSWER
Answered 2021-Oct-14 at 20:04This global undo/redo is a new feature that enables Real Time Collaboration which was added in JupyterLab 3.1. It is indeed sub-optimal for many use cases.
JupyterLab 3.2 allows to disable notebook-wide history tracking (see issue 10791 nad PR 10949), but with a caveat: when moving cells you may loose the undo history, which is why the setting is marked as experimental (it requires more work to be exposed or enabled by a default). To get the selective undo/redo please add:
1{
2 "experimentalDisableDocumentWideUndoRedo": true
3}
4
in Advanced Settings Editor
→ Notebook
, save, and reload JupyterLab (if you use it in a browser a refresh should suffice).
You can also stick with JupyterLab 3.0 if this is a deal breaker. To downgrade you can use pip:
1{
2 "experimentalDisableDocumentWideUndoRedo": true
3}
4pip install "jupyterlab<3.1"
5
or conda:
1{
2 "experimentalDisableDocumentWideUndoRedo": true
3}
4pip install "jupyterlab<3.1"
5conda install -c conda-forge "jupyterlab<3.1"
6
but I would recommend sticking with JupyterLab 3.2 and trying out the new setting so you can contribute to the discussion (if you experience any problems or believe it could be improved).
QUESTION
iPyKernel throwing "TypeError: object NoneType can't be used in 'await' expression"
Asked 2022-Feb-22 at 08:29I know that several similar questions exist on this topic, but to my knowledge all of them concern an async
code (wrongly) written by the user, while in my case it comes from a Python package.
I have a Jupyter notebook whose first cell is
1! pip install numpy
2! pip install pandas
3
and I want to automatically play the notebook using Papermill. No problem on my local machine (Windows 11 with Python 3.7): I install iPyKernel and Papermill and everything is fine.
The problem is when I try to do the same on my BitBucket pipeline (Python image 3-alpine
, but it happens under different others); the first cell throws the following error:
1! pip install numpy
2! pip install pandas
3Traceback (most recent call last):
4 File "/usr/local/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 461, in dispatch_queue
5 await self.process_one()
6 File "/usr/local/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 450, in process_one
7 await dispatch(*args)
8TypeError: object NoneType can't be used in 'await' expression
9
that makes the script stop at the 2nd cell, where I import numpy
.
If it can be relevant, I've "papermilled" under the GitLab CI without any problem in the past.
ANSWER
Answered 2022-Feb-22 at 08:27Seems to be a bug in ipykernel 6.9.0
- options that worked for me:
- upgrade to
6.9.1
(latest version as of 2022-02-22); e.g. viapip install ipykernel --upgrade
- downgrade to
6.8.0
(if upgrading messes with other dependencies you might have); e.g. viapip install ipykernel==6.8.0
QUESTION
"Attempting to perform BLAS operation using StreamExecutor without BLAS support" error occurs
Asked 2022-Feb-21 at 16:09my computer has only 1 GPU.
Below is what I get the result by entering someone's code
1[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456
2locality {} incarnation: 16894043898758027805, name: "/device:GPU:0"
3device_type: "GPU" memory_limit: 10088284160
4locality {bus_id: 1 links {}}
5incarnation: 17925533084010082620
6physical_device_desc: "device: 0, name: GeForce RTX 3060, pci bus id: 0000:17:00.0, compute
7capability: 8.6"]
8
I use jupyter notebook and I run 2 kernels now. (TensorFlow 2.6.0 and also installed CUDA and cuDNN as TensorFlow guide)
The first kernel is no problem to run my Sequential model from Keras.
But when I learn the same code in the second kernel, I got the error as below.
Attempting to perform BLAS operation using StreamExecutor without BLAS support [[node sequential_3/dense_21/MatMul (defined at \AppData\Local\Temp/ipykernel_14764/3692363323.py:1) ]] [Op:__inference_train_function_7682]
Function call stack: train_function
how can I learn multiple kernels without any problem and share them with only 1 GPU?
I am not familiar with TensorFlow 1.x.x version though.
I just solved this problem as below. This problem is because when keras run with gpu. It uses almost all vram. So i needed to give memory_limit for each notebook. Here is my code how i could solve it. You can just change memory_limit value.
1[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456
2locality {} incarnation: 16894043898758027805, name: "/device:GPU:0"
3device_type: "GPU" memory_limit: 10088284160
4locality {bus_id: 1 links {}}
5incarnation: 17925533084010082620
6physical_device_desc: "device: 0, name: GeForce RTX 3060, pci bus id: 0000:17:00.0, compute
7capability: 8.6"]
8gpus = tf.config.experimental.list_physical_devices('GPU')
9if gpus:
10 try:
11 tf.config.experimental.set_virtual_device_configuration(
12 gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=5120)])
13 except RuntimeError as e:
14 print(e)
15
ANSWER
Answered 2021-Oct-12 at 08:52For the benefit of community providing solution here
This problem is because when keras run with gpu, it uses almost all
vram
. So we needed to givememory_limit
for each notebook as shown below
1[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456
2locality {} incarnation: 16894043898758027805, name: "/device:GPU:0"
3device_type: "GPU" memory_limit: 10088284160
4locality {bus_id: 1 links {}}
5incarnation: 17925533084010082620
6physical_device_desc: "device: 0, name: GeForce RTX 3060, pci bus id: 0000:17:00.0, compute
7capability: 8.6"]
8gpus = tf.config.experimental.list_physical_devices('GPU')
9if gpus:
10 try:
11 tf.config.experimental.set_virtual_device_configuration(
12 gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=5120)])
13 except RuntimeError as e:
14 print(e)
15gpus = tf.config.experimental.list_physical_devices('GPU')
16if gpus:
17 try:
18 tf.config.experimental.set_virtual_device_configuration(
19 gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=5120)])
20 except RuntimeError as e:
21 print(e)
22
(Paraphrased from MCPMH)
QUESTION
Running cells with Python 3.10 requires ipykernel installed
Asked 2022-Feb-09 at 09:03I just installed Python 3.10 on my laptop (Ubuntu 20.04).
Running a Jupyter Notebook inside of VS Code works with Python 3.9 but not with Python 3.10. I get the error message: Running cells with 'Python 3.10.0 64 bit' requires ipykernel installed or requires an update
.
Update February 2022
Jalil Nourmohammadi Khiarak gave a more complete answere, it is now the new accepted answer.
Update January 2022
It was a dumb error, I solved my problem (see accepted answer).
Things I tried:
- Clicking on reinstall, which runs:
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2
- Running
pip3 install --upgrade ipykernel jupyter notebook pyzmq
(from this thread).
- As asked in the comments, here is the output when I click the "reinstall" button:
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
3Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
4Traceback (most recent call last):
5 File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
6 return _run_code(code, main_globals, None,
7 File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
8 exec(code, run_globals)
9 File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
10 sys.exit(_main())
11 File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
12 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
13 File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
14 module = importlib.import_module(module_path)
15 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
16 return _bootstrap._gcd_import(name[level:], package, level)
17 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
18 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
19 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
20 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
21 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
22 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
23 File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
24 from pip._internal.cli.req_command import RequirementCommand
25 File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
26 from pip._internal.index.package_finder import PackageFinder
27 File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
28 from pip._internal.index.collector import parse_links
29 File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
30 from pip._vendor import html5lib, requests
31ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
32Traceback (most recent call last):
33 File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
34 subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
35 File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
36 raise CalledProcessError(retcode, cmd)
37subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
38
- Here is what my
_vendor
folder contains:
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
3Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
4Traceback (most recent call last):
5 File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
6 return _run_code(code, main_globals, None,
7 File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
8 exec(code, run_globals)
9 File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
10 sys.exit(_main())
11 File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
12 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
13 File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
14 module = importlib.import_module(module_path)
15 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
16 return _bootstrap._gcd_import(name[level:], package, level)
17 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
18 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
19 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
20 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
21 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
22 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
23 File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
24 from pip._internal.cli.req_command import RequirementCommand
25 File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
26 from pip._internal.index.package_finder import PackageFinder
27 File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
28 from pip._internal.index.collector import parse_links
29 File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
30 from pip._vendor import html5lib, requests
31ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
32Traceback (most recent call last):
33 File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
34 subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
35 File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
36 raise CalledProcessError(retcode, cmd)
37subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
38joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor/
39__init__.py __pycache__
40
- Here is the output of reinstalling pip and checking the
_vendor
file:
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
3Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
4Traceback (most recent call last):
5 File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
6 return _run_code(code, main_globals, None,
7 File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
8 exec(code, run_globals)
9 File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
10 sys.exit(_main())
11 File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
12 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
13 File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
14 module = importlib.import_module(module_path)
15 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
16 return _bootstrap._gcd_import(name[level:], package, level)
17 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
18 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
19 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
20 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
21 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
22 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
23 File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
24 from pip._internal.cli.req_command import RequirementCommand
25 File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
26 from pip._internal.index.package_finder import PackageFinder
27 File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
28 from pip._internal.index.collector import parse_links
29 File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
30 from pip._vendor import html5lib, requests
31ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
32Traceback (most recent call last):
33 File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
34 subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
35 File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
36 raise CalledProcessError(retcode, cmd)
37subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
38joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor/
39__init__.py __pycache__
40joris@joris-N751JK:~$ python3 -m pip install --upgrade --force-reinstall pip
41Defaulting to user installation because normal site-packages is not writeable
42Collecting pip
43 Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
44Installing collected packages: pip
45 Attempting uninstall: pip
46 Found existing installation: pip 21.3.1
47 Uninstalling pip-21.3.1:
48 Successfully uninstalled pip-21.3.1
49Successfully installed pip-21.3.1
50joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor
51__init__.py __pycache__
52
ANSWER
Answered 2021-Nov-02 at 20:03I don't think ipykernel is compatible with 3.10.
Below is the message I receive when I try to install ipykernel with the following command: conda install -c anaconda ipykernel
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
3Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
4Traceback (most recent call last):
5 File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
6 return _run_code(code, main_globals, None,
7 File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
8 exec(code, run_globals)
9 File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
10 sys.exit(_main())
11 File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
12 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
13 File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
14 module = importlib.import_module(module_path)
15 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
16 return _bootstrap._gcd_import(name[level:], package, level)
17 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
18 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
19 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
20 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
21 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
22 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
23 File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
24 from pip._internal.cli.req_command import RequirementCommand
25 File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
26 from pip._internal.index.package_finder import PackageFinder
27 File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
28 from pip._internal.index.collector import parse_links
29 File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
30 from pip._vendor import html5lib, requests
31ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
32Traceback (most recent call last):
33 File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
34 subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
35 File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
36 raise CalledProcessError(retcode, cmd)
37subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
38joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor/
39__init__.py __pycache__
40joris@joris-N751JK:~$ python3 -m pip install --upgrade --force-reinstall pip
41Defaulting to user installation because normal site-packages is not writeable
42Collecting pip
43 Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
44Installing collected packages: pip
45 Attempting uninstall: pip
46 Found existing installation: pip 21.3.1
47 Uninstalling pip-21.3.1:
48 Successfully uninstalled pip-21.3.1
49Successfully installed pip-21.3.1
50joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor
51__init__.py __pycache__
52UnsatisfiableError: The following specifications were found
53to be incompatible with the existing python installation in your environment:
54
55Specifications:
56
57 - ipykernel -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.5,<3.6.0a0|>=3.9,<3.10.0a0']
58
59Your python: python=3.10
60
Solution:
I recommend creating a virtual environment using conda or another library.
To get you started:
- Install Anaconda.
- Enter the following commands. [Note: These are the Windows commands - may vary slightly on Mac and Linux.]
1/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
2/usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
3Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
4Traceback (most recent call last):
5 File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
6 return _run_code(code, main_globals, None,
7 File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
8 exec(code, run_globals)
9 File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
10 sys.exit(_main())
11 File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
12 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
13 File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
14 module = importlib.import_module(module_path)
15 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
16 return _bootstrap._gcd_import(name[level:], package, level)
17 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
18 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
19 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
20 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
21 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
22 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
23 File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
24 from pip._internal.cli.req_command import RequirementCommand
25 File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
26 from pip._internal.index.package_finder import PackageFinder
27 File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
28 from pip._internal.index.collector import parse_links
29 File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
30 from pip._vendor import html5lib, requests
31ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
32Traceback (most recent call last):
33 File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
34 subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
35 File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
36 raise CalledProcessError(retcode, cmd)
37subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
38joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor/
39__init__.py __pycache__
40joris@joris-N751JK:~$ python3 -m pip install --upgrade --force-reinstall pip
41Defaulting to user installation because normal site-packages is not writeable
42Collecting pip
43 Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
44Installing collected packages: pip
45 Attempting uninstall: pip
46 Found existing installation: pip 21.3.1
47 Uninstalling pip-21.3.1:
48 Successfully uninstalled pip-21.3.1
49Successfully installed pip-21.3.1
50joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor
51__init__.py __pycache__
52UnsatisfiableError: The following specifications were found
53to be incompatible with the existing python installation in your environment:
54
55Specifications:
56
57 - ipykernel -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.5,<3.6.0a0|>=3.9,<3.10.0a0']
58
59Your python: python=3.10
60# Create virtual environment
61# Use a version of Python that is less than 3.10
62conda create --name your_env_name python<3.10
63
64# Activate new environment
65conda activate your_env_name
66
67# Install ipykernel
68conda install -c anaconda ipykernel
69
70# Add this new environment to your Jupyter Notebook kernel list
71ipython kernel install --name your_env_name --user
72
73# Windows only: When trying to launch `jupyter notebook`, you may receive a win32api error.
74# The command below fixes that issue.
75conda install -c anaconda pywin32
76
QUESTION
ipykernel (Jupyter notebook/labs) cannot import name ''filefind" from traitlets.utils
Asked 2022-Feb-06 at 10:03I installed Jupyter notebook and labs on and EC2 instance and for some reason I get the following error:
ImportError: cannot import name 'filefind' from 'traitlets.utils' (/usr/lib/python3/dist-packages/traitlets/utils/init.py)
Jupyter opens fine in the browser but I can't seem to be able to work in an python notebook.
ANSWER
Answered 2022-Feb-06 at 09:03Oke fixed it! It seems like the problem was that the "traitlets/utils/init.py" was empty. So I copy-pasted the code from GitHub and that worked.
https://github.com/ipython/traitlets/blob/main/traitlets/utils/__init__.py
I got this problem twice when I installed two different ec2 instances installing cuda and cudnn. So it might that this has something to do with the origins of this issue.
Proper fix:The proper way to fix this problem is by upgrading/downgrading the library. Check the other answers to this post for guidance.
QUESTION
lfortran in a jupyter notebook kills kernel
Asked 2022-Jan-23 at 22:47I can't seem to get output from the lfortran jupyter kernel.
I installed via conda install for:
1 - lfortran
2 - jupyter
3
I can run jupyter
and select the lfortran kernel. However:
I see no hello world and also no error.
If in a second cell I call new
it crashes the kernel.
ANSWER
Answered 2022-Jan-23 at 22:47The global scope in LFortran is special to enable interactivity and usage in a notebook and defines a set of additional rules. You actually don't need a program
body to run any Fortran code there, just using the print statement directly will work:
1 - lfortran
2 - jupyter
3print *, "Hello world!"
4
The extensions to Fortran available are described here.
Further, a program
itself is not supposed to be callable, rather it should execute directly after being declared (this might be a bug in LFortran, reported it in lfortran#648). Instead you might want to declare a subroutine
:
1 - lfortran
2 - jupyter
3print *, "Hello world!"
4subroutine new
5 print *, "Hello world!"
6end subroutine new
7
And than run it with
1 - lfortran
2 - jupyter
3print *, "Hello world!"
4subroutine new
5 print *, "Hello world!"
6end subroutine new
7call new
8
QUESTION
Pandas - How to Save A Styled Dataframe to Image
Asked 2022-Jan-01 at 17:04I have styled a dataframe output and have gotten it to display how I want it in a Jupyter Notebook but I am having issues find a good way to save this as an image. I have tried https://pypi.org/project/dataframe-image/ but the way I have this working it seem to be a NoneType as it's a styler object and errors out when trying to use this library.
This is just a snippet of the whole code, this is intended to loop through several 'col_names' and I want to save these as images (to explain some of the coding).
1import pandas as pd
2import numpy as np
3
4col_name = 'TestColumn'
5
6temp_df = pd.DataFrame({'TestColumn':['A','B','A',np.nan]})
7
8t1 = (temp_df[col_name].fillna("Unknown").value_counts()/len(temp_df)*100).to_frame().reset_index()
9t1.rename(columns={'index':' '}, inplace=True)
10t1[' '] = t1[' '].astype(str)
11
12display(t1.style.bar(subset=[col_name], color='#5e81f2', vmax=100, vmin=0).set_table_attributes('style="font-size: 17px"').set_properties(
13 **{'color': 'black !important',
14 'border': '1px black solid !important'}
15).set_table_styles([{
16 'selector': 'th',
17 'props': [('border', '1px black solid !important')]
18}]).set_properties( **{'width': '500px'}).hide_index().set_properties(subset=[" "], **{'text-align': 'left'}))
19
ANSWER
Answered 2022-Jan-01 at 17:04Was able to change how I was using dataframe-image on the styler object and got it working. Passing it into the export() function rather than calling it off the object directly seems to be the right way to do this.
The .render() did get the HTML but was often losing much of the styling when converting it to image or when not viewed with Ipython HTML display. See comparision below.
Working Code:
1import pandas as pd
2import numpy as np
3
4col_name = 'TestColumn'
5
6temp_df = pd.DataFrame({'TestColumn':['A','B','A',np.nan]})
7
8t1 = (temp_df[col_name].fillna("Unknown").value_counts()/len(temp_df)*100).to_frame().reset_index()
9t1.rename(columns={'index':' '}, inplace=True)
10t1[' '] = t1[' '].astype(str)
11
12display(t1.style.bar(subset=[col_name], color='#5e81f2', vmax=100, vmin=0).set_table_attributes('style="font-size: 17px"').set_properties(
13 **{'color': 'black !important',
14 'border': '1px black solid !important'}
15).set_table_styles([{
16 'selector': 'th',
17 'props': [('border', '1px black solid !important')]
18}]).set_properties( **{'width': '500px'}).hide_index().set_properties(subset=[" "], **{'text-align': 'left'}))
19import pandas as pd
20import numpy as np
21import dataframe_image as dfi
22
23col_name = 'TestColumn'
24
25temp_df = pd.DataFrame({'TestColumn':['A','B','A',np.nan]})
26
27t1 = (temp_df[col_name].fillna("Unknown").value_counts()/len(temp_df)*100).to_frame().reset_index()
28t1.rename(columns={'index':' '}, inplace=True)
29t1[' '] = t1[' '].astype(str)
30
31
32style_test = t1.style.bar(subset=[col_name], color='#5e81f2', vmax=100, vmin=0).set_table_attributes('style="font-size: 17px"').set_properties(
33 **{'color': 'black !important',
34 'border': '1px black solid !important'}
35).set_table_styles([{
36 'selector': 'th',
37 'props': [('border', '1px black solid !important')]
38}]).set_properties( **{'width': '500px'}).hide_index().set_properties(subset=[" "], **{'text-align': 'left'})
39
40dfi.export(style_test, 'successful_test.png')
41
QUESTION
embedding jupyter notebook/ google colab in Django app
Asked 2021-Dec-25 at 13:51I wanted to build a website and embed the jupyter notebook functionality of being able to create cells and run python code within it into my website
For creating a website I m using Django and I would like to embed either the google collab or jupyter notebook
By the way I have researched enough and have been stuck with the StackOverflow links where there no answer about this or the one where they want to use django in jupyter notebook
Thanks in advance for any guidance or any reference that you guys can provide.
ANSWER
Answered 2021-Dec-18 at 05:57Note:: I used "jupyter-lab" you can use "jupyter notebook"
1- The first option to redirect to "jupyter notebook"
django view.py
1from django.shortcuts import redirect,HttpResponse
2import subprocess
3import time
4
5def open_jupiter_notbook(request):
6 b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
7 if "9999" not in b:
8 a=subprocess.Popen("jupyter-lab --no-browser --port 9999".split())
9 start_time = time.time()
10 unreachable_time = 10
11 while "9999" not in b:
12 timer = time.time()
13 elapsed_time = timer-start_time
14 b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
15 if "9999" in b:
16 break
17 if elapsed_time > unreachable_time:
18 return HttpResponse("Unreachable")
19 path = b.split('\n')[1].split('::',1)[0]
20 #You can here add data to your path if you want to open file or anything
21 return redirect(path)
22
if you want to implement it in template instead of redirect, you can use the following code in Django template:
1from django.shortcuts import redirect,HttpResponse
2import subprocess
3import time
4
5def open_jupiter_notbook(request):
6 b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
7 if "9999" not in b:
8 a=subprocess.Popen("jupyter-lab --no-browser --port 9999".split())
9 start_time = time.time()
10 unreachable_time = 10
11 while "9999" not in b:
12 timer = time.time()
13 elapsed_time = timer-start_time
14 b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
15 if "9999" in b:
16 break
17 if elapsed_time > unreachable_time:
18 return HttpResponse("Unreachable")
19 path = b.split('\n')[1].split('::',1)[0]
20 #You can here add data to your path if you want to open file or anything
21 return redirect(path)
22<iframe src="{% url 'open_jupiter_notbook' %}" width= 600px height=200px></iframe>
23
2- The second option:
just use jupyter notebook commands
by using this subprocess.check_output("your command".split())
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Jupyter
Tutorials and Learning Resources are not available at this moment for Jupyter