IPython parallel does not work for me in IPython 2.2 but did in 2.1 - ipython-parallel

the skeleton code of what I do is
from IPython import parallel
.....
rcAll = parallel.Client()
all_engines = rcAll[:]
lbvAll = rcAll.load_balanced_view()
....
for anInpt in allInpt:
lbvAll.apply(mputil.doAll, anInpt)
lbvAll.wait()
lbvAll.get_result()
....
for ijk in range(len(list(lbvAll.results.values()))):
out = list(lbvAll.results.values())[ijk]
ionS = out[0]
However, all that out ever contains is import error messages.
This worked before but but something must have changed between IPython 2.1 and 2.2. At least, that is my guess.

Check the output of:
cat /usr/local/lib/python2.7/dist-packages/*.pth
Delete the following path if it exits inside the "catted" folder:
/usr/lib/python2.7/dist-packages
usr/lib/python2.7/dist-packages being on the front of sys.path means that there is an easy-install.pth file with this path, which should be removed. It is caused by a bug in setuptools.
If that doesn't work, simply upgrading some of your tools might fix the problem.
pip install --upgrade ipython
pip install --upgrade setuptools pip

I found the problem. I started the ipcluster in a shell with a different PYTHONPATH than the one I was running the notebook in. That simple but I took a while. I apologize for the noise.

Related

Drake Mathematical Program Tutorial

I am running Drake on Ubuntu 20.04 using WSL2.
I use python3.8.10 and Drake1.2.0.
I tried running the "Mathematical Program Tutorial" obtained from deepnote on my PC, but the behavior of the ipopt solver is unnatural and does not give the expected results.
The 1st error is occurred in the section using ipopt solver.
All components of the solution is printed as "nan"
The 2nd error is below about "get_solver_details().status"
RuntimeError: The solver_details has not been set yet.
I can see both errors in "Demo on manually choosing a solver" in the tutorial.
The result is following
SolutionResult.kUnknownError
x* = [nan nan]
Solver is IPOPT
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-12-2d1b3835c54a> in <module>
25 print("x* = ", result.GetSolution(x))
26 print("Solver is ", result.get_solver_id().name())
---> 27 print("Ipopt solver status: ", result.get_solver_details().status,
28 ", meaning ", result.get_solver_details().ConvertStatusToString())
RuntimeError: The solver_details has not been set yet.
Thank you in advance.
P.S.
I installed pydrake for venv by pip commands
python3 -m venv env
env/bin/pip install --upgrade pip
env/bin/pip install drake
sudo apt-get install --no-install-recommends \
libpython3.8 libx11-6 libsm6 libxt6 libglib2.0-0
source env/bin/activate
I just download the folder "Tutorial" from deepnote and put it under env.
Then, I run it by Jupyter Notebook as
jupyter notebook
and open env/Tutorials/mathematical_program.ipynb
It turns out that the pip drake == 1.2.0 version has a bug in the IpoptSolver compilation.
As a work-around, you can use SnoptSolver instead, or else use the https://drake.mit.edu/from_binary.html release (unpacking a zipped binary, instead of using pip).
It's possible that the pydrake.solvers.ipopt.IpoptSolver class (which is a wrapper around the https://coin-or.github.io/Ipopt/ library) does not run correctly under WSL2, due to using some odd libc API which doesn't work on Windows. We will need more information to reproduce the problem and try to debug.
Can you state exactly how you installed pydrake (i.e., show us the command lines you used). Was it via pip (https://drake.mit.edu/pip.html) or just via binary (https://drake.mit.edu/from_binary.html)?
Can you state exactly how you ran Jupyter (the command line) to launch the notebook? Was it python3 -m pydrake.tutorials or something else?
Looks like this may not be tied to WSL, but instead pip build (or just binary build). Ran into this on Ubuntu 20.04 (no WSL). Per Drake Slack, filed issue:
https://github.com/RobotLocomotion/drake/issues/17162

Plotly shows blank graphs in AWS Sagemaker JupyterLab

Background: I am new to the Python world and am using Plotly for creating basic graphs in Python. I am using AWS Sagemaker's JupyterLab for creating the python scripts.
Issue: I have been trying to run the basic codes mentioned on Plotly's website however even those are returning blank graphs.
Issue Resolution Tried by myself:
pip installed plotly version 4.6.0
Steps mentioned on https://plotly.com/python/getting-started/ for JupyterLab support have already been executed
Code Example:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
I recently had the same issue. Simple change suggested here helped me. I know this is a temporary workaround until a proper fix is found.
// fig = go.Figure()
fig = go.FigureWidget() // replace with this
// fig.show()
fig // remove .show()
Sagemaker notebook instances are using (As of Jan 2022), for some reason, jupyterlab==1.2.21. You can verify that by running pip freeze | grep lab from the terminal or !pip freeze | grep lab from a notebook.
According to the documentation, you'll need to install the following jupyterlab extensions (which are not needed if sagemaker was running jupyterlab 3):
jupyterlab-plotly
jupyter-widgets/jupyterlab-manager
You can install those on a up-and-running instance by running
jupyter labextension install jupyterlab-plotly#5.5.0 #jupyter-widgets/jupyterlab-manager in the terminal or notebook (using ! if you are running on the notebook ofcourse). Notice that the jupyterlab-plotly extension version (here 5.5.0) should match the plotly version you are installing. Mismatches my cause issues. In this case by plotly version is 5.5.0 and thus that's also the jupyterlab-plotly version I've installed.
If you need, like I did, to have it ready upon spinning up a notebook instance, you'll need to:
Create a lifecycle script
To it, add:
PATH=$PATH:/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin - To ensure nodejs path which is needed for the extension installation
pip install plotly==5.5.0 - To ensure a specific version
jupyter labextension install jupyterlab-plotly#5.5.0 #jupyter-widgets/jupyterlab-manager - To ensure same version
of coures, you can change the version according to the most up to date.
I think that documentation is not on par. You now need to install jupyterlab-plotly extension.
jupyter labextension install jupyterlab-plotly
UPDATE
I followed a mix of instructions here and here.
First Enable Extention manager from jupyter-lab
then from terminal
conda install -c conda-forge "nbformat" "ipywidgets>=7.5" -y
jupyter labextension install jupyterlab-plotly
jupyter labextension install #jupyter-widgets/jupyterlab-manager plotlywidget
And within your environment
conda install nbformat

`roslaunch rosbridge_server rosbridge_websocket.launch` requires to deactivate venv

I have a project with venv that works just fine, but when we need to run roslaunch rosbridge_server rosbridge_websocket.launch it will result in the error below unless we deactivate venv.
process[rosbridge_websocket-2]: started with pid [10182]
process[rosapi-3]: started with pid [10183]
Failed to load Python extension for LZ4 support. LZ4 compression will not be available.
Failed to load Python extension for LZ4 support. LZ4 compression will not be available.
registered capabilities (classes):
-
-
-
-
-
-
-
-
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/rosbridge_server/rosbridge_websocket", line 44, in
from rosbridge_server import RosbridgeWebSocket, ClientManager
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosbridge_server/init.py", line 4, in
from .udp_handler import RosbridgeUdpSocket,RosbridgeUdpFactory
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosbridge_server/udp_handler.py", line 6, in
from twisted.internet.protocol import DatagramProtocol,Factory
ImportError: No module named 'twisted'
I am assuming this is because there's no module named twisted installed in the virtual environment but it is installed on my computer. Following this hypothesis, this means that making roslaunch rosbridge_server rosbridge_websocket.launch work would require to install all the dependencies that it needs in venv? How would one go to do that?
This is a bit late, but what version of python are you targeting with venv? I suspect it's a python 3.x, and if so, you have to setup for it.
As you suspect, you're missing packages, this should be a good start (from here), adjusting the commands to suit your venv.
sudo apt-get install python3-pip python3-yaml
sudo pip3 install rospkg catkin_pkg
For more details, see the new ros wiki pages: http://wiki.ros.org/UsingPython3/IdentifyDependencies
just make sure the version of python you are using in venv and the environment where those packages are installed is same, if thats not the case, then you probably need to correct the python paths.
Mostly when you are running something in venv, the interpreter will only look inside that virtual environment, so when i face that issue, i just stopped using venv for ros and exported the pythonpaths or any ros module if they are installed for python3. distribution.

Google Assistant service for Raspberry Pi zero - Illegal Instruction

Installation on Pi zero.
The installation was successful, but when I tried sample code
googlesamples-assistant-hotword --project_id my-dev-project --device_model_id my-model
It returns Illegal Instruction.
The pushtotalk sample didn't work neither.
Appreciate the help.
I finally got the assistant to work on Pi 0 with pushtotalk sample by installing python -m pip install --upgrade --no-binary :all: grpcio before the SDK installation.
However, the assistant will either take forever to give me NO response or not able to finish the response, in either situation, I'll have to close the terminal to end the session. I've opened an issue in github, and it seems like an incompatibility error in the gRPC package. https://github.com/googlesamples/assistant-sdk-python/issues/267
The hotword sample uses the Google Assistant Library, which is not available on the Raspberry Pi Zero.
try run again
python -m pip install --upgrade google-assistant-library
python -m pip install --upgrade google-assistant-sdk[samples]
Been having the same problem with raspberry pi 1. Only solution I could find so far is to use the pushtotalk and have echo automatically input newline using this.
googlesamples-assistant-pushtotalk --project-id gassist-d4d83 --device-model-id gassist-d4d83-rpi-meicej|echo -n
That does the job for me. Don't know if it helps anyone.
Edit: Only part that's bad is, it's always listening. Maybe I can modify the code.

Dataflow wordcount.py example " Import by filename is not supported"

Using Ubuntu 14.04,
DataFlow Python SDK
Following instructions at [https://github.com/GoogleCloudPlatform/DataflowPythonSDK#status-of-this- release] , after everything is loaded when I try the wordcount example I try get the error "Import by filename is not supported".
I suspect the issue is at line 23 of the wordcount.py example
import google.cloud.dataflow as df
Is there a workaround for this issue?
I have tried the solution posted at Python / ImportError: Import by filename is not supported , but that does not solve the problem.
Since this fails at the first import statement the immediate thing to check is if the Python Dataflow package is installed at all. Th way to do that is by running 'pip freeze'. Here is some output from running this in a virtual environment:
$ pip freeze
... Nothing since it is a clean virtual environment ...
$ pip install https://github.com/GoogleCloudPlatform/DataflowPythonSDK/archive/v0.2.3.tar.gz
... Output from installing packages ...
$ pip freeze
...
python-dataflow==0.2.3
...
Now you can run python and execute 'import google.cloud.dataflow as df' and it should work.
Hopefully this helps!

Resources