How can I make the Lux package work in Python? - python

I was trying to use the package called LUX for Python. I followed this tutorial. So it was pretty simple, I just had to import some csv and when I called my data, I would be able to see multiple graphs. The problem is that I do everything and nothing shows up for me.
I was using Melbourne House Market data, and this is my script so far:
# firstly, we install package and extensions
!pip install lux-api
!jupyter nbextension install --py luxwidget
!jupyter nbextension enable --py luxwidget
# then, load the packages
import lux
import pandas as pd
# load data
melb_data = pd.read_csv("melb_data.csv")
So far so good... at least, I thought so. After doing these things, when we see the tutorial mentioned in the begining of this question, it mentions that if we call the dataframe now, instead of appearing only the dataset, we would be able to see some graphics as well. But that didn't happen to me. I know screenshots are not the best choice, but this is what I see:
As you can see, there is the Toggle button, but it is only working to hide the table. there isn't the graphs I saw in the tutorial. I also tried to follow this tutorial as well, but there isn't anything new there.
Any ideas on what I'm missing here? Why I can't find a way to make this package work?

It seems that you have not installed the JuypterLab extension. It is described in the README file that you linked, here. You will need to execute the following two commands:
jupyter labextension install #jupyter-widgets/jupyterlab-manager
jupyter labextension install luxwidget
and then restart JupyterLab. The prerequisite here is having a JupyterLab 2.x or 3.x and Node.js installed (while many extensions for JupyterLab 3.x do not require node.js any longer, this one still does - as it seems).

Related

`pipreqs` generating blank requirements.txt in Docker Container

I am using Python in a Jupyter Lab notebook in a Docker container. I have the following code in one cell:
import numpy as np
import os
import pandas as pd
Then I run the following cell:
!pipreqs /app/loaded_reqs
and get:
INFO: Successfully saved requirements file in /app/loaded_reqs/requirements.txt
But when I open the requirements.txt, it shows up empty/blank. I expected numpy, os and pandas to be in this requirements.txt file. Why might it not be working?
According to this Medium post by Iván Lengyel, pipreqs doesn't support Jupyter notebooks. (This issue in in the pipreqs repo, open since 2016 convinces me of the veracity of that assertion. Nicely, the issue post also suggests the solution I had already found when searching the terms 'pipreqs jupyter' at Google.) Plus, importantly you generally don't use tools that act on notebook files inside the notebook you are trying to use. (Or at least it is something to always watch out for, [or test if possible], similar in a way to avoiding iterating on a list you are modifying in the loop.)
Solution -- use pipreqsnb instead:
In that Medium post saying it doesn't work with notebooks, Iván Lengyel proffers a wrapper for it that works for notebooks. So in the terminal outside the notebook, but in the same environment (inside the docker container, in your case), install pipreqsnb via pip install pipreqsnb. Then run it pointing it at your specific notebook file. I'll give an example in the next paragraph.
I just tried it and it worked in temporary sessions launched from here by pressing launch binder badge there. When the session came up, I opened a terminal and ran pip install pipreqsnb and then pipreqsnb index.ipynb. That first time I saw requirements.txt get made with details on the versions of matplotlib, numpy, scipy, and seaborn. To fully test it was working, I opened index.ipynb in the running session and added a cell with import pandas as pd typed in it and saved the notebook. Then I shutdown the kernel and over in the terminal ran, pipreqsnb index.ipynb. When I re-examined the requirements.txt file now pandas has been added with details about the versions.
More about maybe why !pipreqs /app/loaded_reqs failed:
I had the idea that maybe you needed to save the notebook first after adding the import statements cell? However, nevermind. That still won't help because as stated here pipreqs, and further confirmed at the pipreqs issues list doesn't support Jupyter notebooks.
Also, keep in mind the use of the exclamation in a notebook to run a command in the shell doesn't mean that shell will be in the same environment as the kernel of the notebook, see the second paragraph here to more perspective on that. (This can be useful to understand for future things though, such as why you want to use the %pip or %conda magic commands when installing from inside a notebook, see here, and not put an exclamation point in front of that command in modern Jupyter.)
Or inside the notebook at the end, I'd suggest trying %watermark --iversions, see watermark. And then making some code to generate the requirements.txt from that. (Also, I had seen there was bug in that related to some packages imported with from X import Y, see here.)
Or I'd suggest trying %pip freeze inside the notebook for the full environment information. Not just what the file needs, though.

Jupyter notebook renders text instead of ipywidgets

My Jupyter notebook is displaying text rather than ipywidgets. Here is a screenshot:
I read several posts about similar problems, like this one:
Jupyter Notebook not rendering ipywidgets.
Most of them indicate that the solution is to enable an extension, e.g: https://stackoverflow.com/a/38001920/11692496
But it seems to apply to older version of jupyter notebooks. I tried it anyway (with the --sys-prefix argument, which is required for virtualenv), but it didn't fix it.
I'm working with a jupyter notebook and a virtualenv. Just to be sure, I created a fresh venv and installed the minimal packages. No luck.
I'm using Python 3.10.6 and here is my versions list:
Thanks for your help!
For the record, I didn't manage to solve this issue on my virtualenv.
As #Wayne suggested above, I went for a workaround, namely a docker container based on jupyter/tensorflow-notebook

`ipywidgets.interact` shows the widget itself but does not apply the function in the argument (Jupyter Notebook)

I have a problem that interactive objects from ipywidgets do not work in Jupyter Notebook on my computer. The widget itself is displayed but the function that it should control (e.g. drawing graph with changing parameter), seemingly, does not run. I took example from documentation and it does not work.
The picture of code and output
Code:
import ipywidgets
import widgetsnbextension
def greeting(text="World"):
print("Hello {}".format(text))
ipywidgets.interact(greeting, text="IPython Widgets")
What have I already tried:
There were similar questions, like this but the answer didn't work for me (the answer was to run this:
jupyter nbextension enable --py widgetsnbextension).
The code above works in GoogleColab so I tried to install their versions of packages ipython and ipykernel (packages ipywidgets and widgetsnbextensions were of the same version as mine). But it has led to errors so I have given up this idea. I have the latest versions of all packages now and I don't have Anaconda.
What should I try next? May be I am wrong and the problem has a different cause?
I found the answer!!!
I have had several nbextensions switched on (see screenshot). This was my mistake to include everything which seemed useful. When I turned off all nbextensions then all ipywidgets stuff started to work. Finally, I found that one particular extension called Limit Output is to be blamed for. Turn it off and all works fine.
The moral: don't use everything if you don't need it. Also, obviously, there is a bug in Limit Output extension because it is not supposed to affect widgets (it is supposed to limit output data when you accidentally write while(true) or something like that).
You can read some useful stuff about SageMath in the comments under the original question as well.

Using Matlab.engine and installing tensorflow at the same time

Currently I am working on a project with Jupyter Notebook in which I need to run a matlab script (.m) which includes a function that provides me with data which i try to solve with a tensorflow model afterwards. I can set up an environment that runs the matlab code an gives me the data and I can set up an environment that does the tensorflow thing but my problem is I can`t do it in the same environment.
Here is the setup and the problems. I am using matlab.engine which I installed like described here: https://de.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
To run my Jupyter Notebook I first navigate to the location where my python.exe and the matlab files are lying ("C:\Users\Philipp\AppData\Local\Programs\Python\Python37-32\Scripts"). If I try to run pip install tensorflow (in Anaconda Prompt) I got a lot of different errors like the following. Conda install works but even when it is installed i can`t import it.
ImportError: No module named 'tensorflow.core' or
ERROR: Could not find a version that satisfies the requirement tensorflow or just No module named 'tensorflow'
I searched for all those problems but nothing helped me. I think this has something to do with the directory I am working in and I know it is bad but I have no idea how to change that. The error also occurs in different environments.
Have you tried running !pip install tensorflow directly in Jupyter Notebook? It's a temporary workaround, but I am having the same problems and this one helped. Remember to comment it out after installation, so you wont re-run it by accident.
I found a solution to my problem. For this I needed a Jupyter Notebook and an external .py script that I design as a Flask. I can luckily run those in different environments. I past and request the data from the server by using "get" and "post".
If someone still has another idea to do all this in one JN, I would still be happy about answers.

Google colab: problems with pyvistaqt

I'm using colab for doing my projects. Right now I have a problem pyvistaqt, I'm not sure if that python package can use on colab, because I already installed but at the moment to run:
plot_sensors_connectivity(epoch.info, con[:,:,0])
appear the following error:
QtDeprecationError: BackgroundPlotter has moved to pyvistaqt.
You can install this from PyPI with: pip install pyvistaqt
See https://github.com/pyvista/pyvistaqt
As far as I know, you can't display a pyqt widget within a jupyterlab environment, so anything you're trying to do right now using Qt should be avoided. My guess is that plot_sensors_connectivity uses pyvista.BackgroundPlotter, and instead should just use pyvista.Plotter.

Categories

Resources