how to set python module path to jupyter notebook - path

I am trying to use object_detection API in google cloud notebook. I followed installation instruction. It appears that I have no problem to import api in python3.
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import object_detection
>>> from object_detection.utils import dataset_util
2019-09-12 08:53:29.964341: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
However, I was not able to do same thing in jupyter notebook.
Ok. According to what I can find on_line. I tried following things: (1) cd $home (2)nano .bashrc (3) add one line:
export JUPYTER_PATH="/home/jupyter/Tensorflow/models/research/":$JUPYTER_PATH
It turns out this didn't work neither. I am not sure if there is anything I did wrong.
Any suggestion is highly appreciated.
Thanks.

#derec after you have added the required line, type this command: source .bashrc.
This executes the .bashrc file and then close the terminal window.
Whenever you edit .bashrc file, always put the above mentioned command after editing it.

Related

No module named 'manipulation'

I am using Ubuntu 22.04 LTS via WSL and working on Python 3.10. When I try to run Drake tutorials locally with python3 -m pydrake.tutorials I get the following error: ERROR: the Jupyter notebook runtime is not installed! which is not the case since I already installed jupyter-notebook using sudo apt-get install jupyter-notebook and can easily open a jupyter notebook myself when typing jupyter notebook.
Additionally, I tried to copy-paste and run the following code from a tutorial:
import pydot
from IPython.display import HTML, SVG, display
from pydrake.all import (AddMultibodyPlantSceneGraph, DiagramBuilder,
FindResourceOrThrow, GenerateHtml,
InverseDynamicsController, MeshcatVisualizer,
MeshcatVisualizerParams, MultibodyPlant, Parser,
Simulator, StartMeshcat)
from manipulation import running_as_notebook
and i get the following error:
ModuleNotFoundError: No module named 'manipulation'
It seems as I don't have a module called manipulation except the one inside pydrake library. Is this a version issue?
I desired to mention it in case the two errors are interconnected.
None of the tutorials in Drake import anything from manipulation. The manipulation textbook repository examples absolutely do. You can find more about those here: https://manipulation.csail.mit.edu/drake.html .

Spyder IDE tells me my python version is incorrectly compiled (MAC)

I just downloaded Spyder IDE for my programming class. I had been using Replit for two months, so I figured this is high time I switched to Spyder.
The console shows this message:
"This version of python seems to be incorrectly compiled
(internal generated filenames are not absolute).
This may make the debugger miss breakpoints.
Related bug: http://bugs.python.org/issue1666807"
NOTE: I had installed Python a year ago using Atom, but then today, before installing Spyder, I deleted Python and all files related to it. Then, I downloaded latest version of Python from Python's website (3.10.1).
I tried to find a work around for this by going to preferences, Python interpreter, and selecting the interpreter I downloaded, which is named Python IDLE. But, every time I try selecting that, it says invalid file path (/Applications/Python 3.10/IDL
I tried looking this up, but I cannot find something that is beginner-friendly. Can someone help me understand what is causing this?
I tried to add conda-forge as prioritized channel, and I created new environment to install python and spyder-kernel again.
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install
https://conda-forge.org/#about
I was thinking about clear my default 'base' environment, but that does not work well. Thus, I had to create new environment.
conda create --name myenv
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands
After that I have to indicate new Python Interpreter on 'Preferences - Python Interpreter - Use the following Python Interpreter'.
Then, it works for now, but I have to install additional packages for my convenience later.
In conclusion, I can have Spyder application running through Rosetta 2 with Python Interpreter for Apple Silicon.
Python 3.10.2 | packaged by conda-forge | (main, Jan 14 2022, 08:04:21) [Clang 11.1.0 ]
Type "copyright", "credits" or "license" for more information.
IPython 8.0.1 -- An enhanced Interactive Python.
My answer might be so rough, so please let me know how can I improve.

pydrake is not available for installation anymore through google colab?

I have been using a google colab template for iterative LQR that uses the Pydrake, however, it seems like the code repository is removed and I can't reinstall it on google Colab:
try:
import pydrake
import underactuated
except ImportError:
!curl -s https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py > jupyter_setup.py
from jupyter_setup import setup_underactuated
setup_underactuated()
# Setup matplotlib backend (to notebook, if possible, or inline).
from underactuated.jupyter import setup_matplotlib_backend
plt_is_interactive = setup_matplotlib_backend()
File "/content/jupyter_setup.py", line 1
404: Not Found
^
SyntaxError: invalid syntax
I tried clicking this link https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py, and the page is not found... everything was working fine yesterday
Sorry. You're correct... I updated it this morning, and don't have a good deprecation policy in place on that repo, and this setup script is two versions ago. The path you want is https://raw.githubusercontent.com/RussTedrake/underactuated/master/setup/jupyter_setup.py
(remove the script from the directory). But if you look at that file, you'll see that even that is pointing to an updated setup script which you might want to point to.
This is actually all good news... we are on the path to a much better solution. You can now just pip install drake on colab (see the drake installation guide). Once I land the pip install underactuated (probably in time for my Spring offering of the class), then all of that nasty setup will be gone.

Spyder not handling relative imports

I am attempting to python3 proof my work and spyder seems to be having an issue with absolute_import.
For demonstration purposes I created two simple files. caller and callme
caller
from __future__ import absolute_import
from .callme import helloWorld
def runme(msg):
helloWorld(msg)
if __name__ == "__main__":
runme('It worked!')
callme
def helloWorld(msg):
print("helloWorld's message is '{}'".format(msg))
if __name__ == "__main__":
helloWorld('Hi')
When attempting to run caller from spyder I get the following error:
ValueError: Attempted relative import in non-package
Running from ipython via the anaconda prompt (python 2) or from jupyter notebook (running python3 or python2) both work properly.
Ideas on how to fix spyder's behavior so it properly recognizes absolute_import?
Spyder versions tried:
3.2.4 Python 2.7.14 64bits, Qt 5.6.2, PyQt5 5.6 on Windows 10
3.3.2 Python 2.7.14 64-bit | Qt 5.6.2 | PyQt5 5.6 | Windows 10
Update
Updating spyder via conda update spyder (now version 3.3.2) did not fix the issue.
If you run python caller.py in a system terminal, you'll get exactly the same error as the one you posted, i.e.
ValueError: Attempted relative import in non-package
So this is not a problem with Spyder (because Spyder runs something similar to python caller.py when you execute a file with Run > Run), but with the way relative imports works.
Please see this answer for a proper explanation:
https://stackoverflow.com/a/11537218/438386
In essence, you can't use relative imports in scripts.
Note: There's a workaround to avoid this error, as described in this answer:
https://stackoverflow.com/a/11536794/438386
However, we don't have the ability to execute a script as a package in Spyder, sorry.

How to install OpenCV 3.0 with nonfree module?

I've tried a few times but most guides out there only tell you how to install it AFTER you've built OpenCV. I've had 2 unsuccessful attempts doing it this way and it's been a lot of work to do it this way, so
I'd appreciate (and other people reading later might appreciate) basic instructions on how to install it (assuming dependencies are already there).
Is it best to use git or build it yourself?
What instructions must cmake be run with?
Is it better to just build an old version (say 2.4.9) since version 3 is unreliable so far?
There is an answer by Berak on the opencv forums to this question, quoted below. Essentially you can pull it down from Git, add it during the cmake process and you are good to go.
Beraks answer:
in 3.0, SIFT and SURF were moved to the opencv_contrib repo
you will need to clone/fork/download that, and add that to your (main
opencv) cmake;
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules
then, after building,
#include "opencv2/xfeatures2d/nonfree.hpp"
Ptr<xfeatures2d::SURF> surf = xfeatures2d::SURF::create(); // note
extra namespace surf->detect(...); surf->compute(...);
don't forget to link to opencv_xfeatures2d(.lib)
Also, in answer to Question #4. OpenCV 3.0 is fine, I wouldn't say it was unreliable.
FINALLY FOUND THE SOLUTION :
First configured "opencv-3.4" with required stuff. I found easy to use cmake-gui to configure opencv-3.4 . During configuration enabled "OPENCV_ENABLE_NONFREE" by selecting the check box and other required stuff.
Compilation went well and make install also done.
But i couldn't able to use the "nonfree" api like "xfeatures2d" which are used as part of my application.
After 6-7hrs of effort , finally found that we need to include "opencv-contrib" module during configuration of opencv.
Downloaded opencv-contrib-3.4.8 and given till "../opencv-contrib-3.4.8/modules" during opencv configuration in OPENCV_EXTRA_MODULE_PATH
Then did configure using cmake-gui , now i can see below configuration happening from "opencv_contrib" and extra modules has been picked by opencv. End of configure did make and make install.
xfeatures2d/boostdesc: Download: boostdesc_bgm.i
xfeatures2d/boostdesc: Download: boostdesc_bgm_bi.i
xfeatures2d/boostdesc: Download: boostdesc_bgm_hd.i
xfeatures2d/boostdesc: Download: boostdesc_binboost_064.i
xfeatures2d/boostdesc: Download: boostdesc_binboost_128.i
xfeatures2d/boostdesc: Download: boostdesc_binboost_256.i
xfeatures2d/boostdesc: Download: boostdesc_lbgm.i
xfeatures2d/vgg: Download: vgg_generated_48.i
xfeatures2d/vgg: Download: vgg_generated_64.i
xfeatures2d/vgg: Download: vgg_generated_80.i
xfeatures2d/vgg: Download: vgg_generated_120.i
data: Download: face_landmark_model.dat
..
How to test whether "nonfree" module included in opencv:
login to your virtual environment and type "python" , then "import cv2" (should return without error) . Then finally did "surf=cv2.xfeatures2d.SURF_create()" which also returns with no error. This included that "nonfree" modules are added in opencv.
>$ python
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import cv2
>>>
>>> surf=cv2.xfeatures2d.SURF_create()
>>> exit()
Thanks,
Muthukumar

Resources