can not find nbconvert.py after git clone and pip install nbconvert - python

I am following the instruction here http://www.slideviper.oquanta.info/tutorial/slideshow_tutorial_slides.html#/10 to convert my ipynb file to a html slideshow.
As I didn't have nbconvert, I $git clone https://github.com/jupyter/nbconvert.git and $pip install nbconvert. Everything looked good.
In my folder $ls returns CONTRIBUTING.md COPYING.md docs MANIFEST.in nbconvert README.md readthedocs.yml scripts setup.cfg setup.py
Here I could not find python nbconvert.py
As nbconvert is a folder, I $cd nbconvert and $ls. It showed:
exporters __init__.py nbconvertapp.py preprocessors templates utils writers
filters __main__.py postprocessors resources tests _version.py
Still, I did not see nbconvert.py I tried $python nbconvertapp.py -f reveal myfile.ipynb, the error:
File "nbconvertapp.py", line 26, in <module>
from .exporters.export import get_export_names, get_exporter
ValueError: Attempted relative import in non-package`
I am not clear what's going on here. Could someone direct me the right way to insall or use nbconvert so I can translate my ipynb file to a html slideshow? Thank you!

You should add c:\python27\Script\jupyter.exe (or wherever this file is) to the windows path, then you should cd to where your .ipynb file is and type in a windows cmd console :
jupyter nbconvert youfile.ipynb format
"format" can be : html, slides, pdf, etc...
Good luck

Since you are importing a module, the package for nbconvert are installed in your base python path and is accessible anywhere you have access to python. Therefore the correct way to use nbconvert is:
jupyter nbconvert <command>
If you run just:
jupyter nbconvert
you will see help information on commands it receives

Related

Jupyterlab i18next: How to extract translatable strings from JupyterLab notebooks?

I would like to offer my JupyterLab notebooks in several languages (de-de, en-us).
In order to do so, I marked some strings
import gettext
domain = 'my_application_name'
localedir = '.'
translate = gettext.translation(domain, localedir, fallback=True)
_ = translate.gettext # using _ as name for the translation function is kind of standard in python
# do not confuse with private markers or underscore library
# https://github.com/serkanyersen/underscore.py
print(_('Hello World'))
print(_('another translation key'))
Then I downloaded xgettext.exe for windows from
https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.21-v1.16/gettext0.21-iconv1.16-static-64.zip
and tried to extract the strings with following console command:
xgettext.exe my_notebook.ipynb
I got the warning
xgettext.exe: warning: file 'my_notebook.ipynb' extension 'ipynb' is unknown; will try C
and no output file was generated.
=> What is the recommented way for extracting translatable strings from JupyterLab notebooks?
I would prefer a solution, where no extra binary (like xgettext.exe) would be required on windows.
Does JupyterLab itself provide some translation features/extension (not for the UI but for notebooks)?
As a possible workaround, the notebook could first be converted to a python file with nbconvert and then passed to xgettext.exe. However, that seems to be too complicated. There should be a more elegant solution.
(The extraction of translatable strings from python files does work on windows, e.g.
xgettext.exe my_python_file.py
)
The rough workflow for translations seems to be:
Mark all strings that should be translated
Generate a translation file template from the strings (="master list" or Portable Object Template (POT) file)
Translate the translation file template
Apply the translation file
Related:
https://github.com/jupyterlab/jupyterlab/issues/11753
https://docs.python.org/3/library/i18n.html
https://www.mattlayman.com/blog/2015/i18n/
Here is the already mentioned workaround based on nbconvert and xgettext:
jupyter nbconvert --to script my_notebook.ipynb --output z_temp_file_for_translation
xgettext.exe z_temp_file_for_translation.py -o translations.pot
del z_temp_file_for_translation.py
As an alternative to xgettext, the python package Babel can be used:
pip install Babel
Also see: http://babel.pocoo.org/en/latest/cmdline.html#extract
jupyter nbconvert --to script my_notebook.ipynb --output z_temp_file_for_translation
pybabel extract z_temp_file_for_translation.py -o translations.pot
del z_temp_file_for_translation.py

I can't run tf_upgrade_v2 to migrate to tensorflow 2

I try to do the following steps to migrate from TensorFlow 1 to TensorFlow 2: https://www.tensorflow.org/guide/upgrade. I can do this in Google Colab but I can't do this on my laptop.
To do so, I first tried to run the following command in Powershell (I'm on Windows, also my working directory contains the project folder):
tf_upgrade_v2 --intree project/ --outtree project2/ --reportfile report.txt
It says that "The term 'tf_upgrade_v2' is not recognized ..."
Then, I downloaded file tf_upgrade_v2.py from the TensorFlow repository and tries to run the following command:
python tf_upgrade_v2.py --intree project/ --outtree project2/ --reportfile report.txt
It works for some time, then finishes, but there is no changes in the folder.
Finally, I tried this:
tf_upgrade_v2.py --intree project/ --outtree projects2/ --reportfile report.txt
It opens another terminal for some time, then finishes, but there is no changes.
I have TensorFlow 2.0 according to pip list. I use conda
UPD:
conda list doesn't contain tensorflow, only tensorboard, tensorflow-estimator, tensorflow-hub
I had the same issue, running python on windows using Visual Studio 2019. The short version, if you already know the location of the upgrade script, is instead of tf_upgrade_v2.py I needed to run tf_upgrade_v2_main.py as the former simply ran and did nothing.
Detailed steps:
The actual steps to running the upgrade script were more involved to figure out. TLDR; from the folder where you want to perform the upgrade run the following command:
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python" "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\site-packages\tensorflow\tools\compatibility\tf_upgrade_v2_main.py" --infile NeuralTransfer-tf1.py --outfile NeuralTransfer-tf2.py
Be sure to replace C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\ with the path to your python install directory as needed. Also be sure to set the --infile and --outfile arguments accordingly.
To locate tf_upgrade_v2.py, which per the documentation should be installed with TensorFlow 1.13 and later (including all TF 2.0 builds), simply search for the file in your python install directory in windows explorer.
In my case tf_upgrade_v2.py was located (relative to the install directory) in Lib\site-packages\tensorflow\tools\compatibility\tf_upgrade_v2_main.py as shown in the command line arguments above.
It can be also located under c:\users\user\appdata\roaming\python\python_xx\site-packages (if pip is used pip show tensorflow can be used)
For colab run this:
os.environ.get("tf_upgrade_v2")
And then this:
!tf_upgrade_v2 \
--intree xyz \
--outtree zyx \
--reportfile xyzyx
For me it is working by following line of code.
!tf_upgrade_v2 \
--intree models/xyz/cookbook/ROL/ \
--outtree Rol_v2/ \
--reportfile tree_report.txt

ImportError: cannot import name 'input_reader_pb2'

working on win10 64-bit
when i trying to train my model by E:\projectx\model-master\models-master>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config
this error appear
File "train.py", line 49, in
from object_detection.builders import dataset_builder
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\dataset_builder.py",
line 27, in
from object_detection.data_decoders import tf_example_decoder
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\data_decoders\tf_example_decoder.py",
line 27, in
from object_detection.protos import input_reader_pb2
ImportError: cannot import name 'input_reader_pb2'
i do run protoc 3.4 protoc object_detection/protos/*.proto --python_out=.
but the error still exist
i check all thing and it is should be fine and work, it is going me mad!!
please help....
thanks
As you already compiled all .proto files in object_detection/protos/ . You should see python files which have '_pb2' like eval_pb2. If you can see these then go to models/research directory and run these code one by one:
python setup.py build
python setup.py install
From inside the object_detection folder:
protoc ../object_detection/protos/*.proto --python_out=.
This command will generate a *_pb2.py for each .proto file in the object_detection/protos/ folder.
Note: Is important to specify a path above object_detection, otherwise errors would occur, most likely:
object_detection/protos/ssd_anchor_generator.proto: File not found.
protos/anchor_generator.proto:8:1: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
protos/anchor_generator.proto:17:5: "FlexibleGridAnchorGenerator" is not defined.
If the error persists probably you are in the wrong folder, take a look at the output message to see from where it is trying to import the file and execute the command in the right directory.
As last resort: Download the object_detection module from https://github.com/tensorflow/models/tree/master/research
place it in your working directory, enter it and re-execute the command above.
It will surely works as local modules have import priority over sys.path.
If not, the error message would be probably different from the one reported and the problem lies on the tensorflow installation or the protobuf compiler; as here where the problem was caused by the protoc version.
other useful links: https://github.com/tensorflow/models/issues/5264
Maybe you haven't added module slim to PYTHONPATH.It can be done by running below code inside models/research directory.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Seems that you didnt compile protobuf.
For solving it:
Download the latest protoc exe here: https://github.com/google/protobuf/releases (in your case should be win32)
Rename that folder to "protoc"
Put that folder inside models/research
in models/research via console, launch:
protoc/bin/protoc object_detection/protos/*.proto --python_out=.
I dont know exactly if that command will work on windows, but you have to be sure that you are using the protoc compiler that you downloaded (v.3.6) instead of the protoc in your enviroment.

ModuleNotFoundError: No module named 'object_detection'

i try to train.py in object_detection in under git url
https://github.com/tensorflow/models/tree/master/research/object_detection
However, the following error occurs.
ModuleNotFoundError: No module named 'object_detection'
So I tried to solve the problem by writing the following code.
import sys
sys.path.append('/home/user/Documents/imgmlreport/inception/models/research/object_detection')
from object_detection.builders import dataset_builder
This problem has not been solved yet.
The directory structure is shown below.
~/object_detection/train.py
~/object_detection/builders/dataset_bulider.py
and here is full error massage
/home/user/anaconda3/lib/python3.6/site-packages/h5py/init.py:34: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated.
In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "train.py", line 52, in
import trainer
File"/home/user/Documents/imgmlreport/inception/models/research/object_detection/trainer.py", line 26, in
from object_detection.builders import optimizer_builder
ModuleNotFoundError: No module named 'object_detection'
how can i import modules?
Try install Tensorflow Object Detection Library Packaged
pip install tensorflow-object-detection-api
Cause of this error is installing object_detection library, So one of the solution which can work is running the below command inside models/research
sudo python setup.py install
If such solution does not work, please execute the below command one by one in the directory models/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
sudo python setup.py install
I hope this will work. I also faced the same problem while creating model from export_inference_graph.py. It worked for me.
You need to export the environmental variables every time you open a new terminal in that environment.
Please note that there are are back quotes on each of the pwd in the command as this might not be showing in the command below. Back quote is the same as the tilde key without pressing the shift key (US keyboard).
From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
try this:
python setup.py build
python setup.py install
There are a number of modules in the object_detection folder, and I have created setup.py in the parent directory(research folder) to import all of them.
from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = ['Pillow>=1.0', 'Matplotlib>=2.1', 'Cython>=0.28.1']
setup(
name='object_detection',
version='0.1',
install_requires=REQUIRED_PACKAGES,
include_package_data=True,
packages=[p for p in find_packages() if p.startswith('object_detection')],
description='Tensorflow Object Detection Library',
)
You did have "sys.path.append()" before you imported the object detection, so I am surprised that you are facing this error!
Please check that the path you have used in sys.path.append() is right.
Well, the only and obvious answer for the error is that the path of the module is not added properly.
Besides the various ways mentioned here, here is a way in which you can add the "object_detection" path permanently to the PYTHONPATH variable.
If you are using a Linux system, here is how you would go about it:
Go to the Home directory. Press Ctrl + H to show hidden files. You will see a file called ".bashrc". Open this file using a code editor (I used Visual Studio).
In the last line of .bashrc file, add the line:
export PYTHONPATH=/your/module/path:/your/other/module/path:your/someother/module/path
Then press "save" in the code editor. Since ".bashrc" is a "Read-only" file the editor will throw a pop-up saying the same. Also in the pop-up there will be an option that says: "Try with sudo". Hit this button and now you are good to go.
All your modules are now permanently added to the PYTHONPATH. This means that you need not run sys.path.append every time you open your terminal and start a session!
Below is the screenshot with no error when I followed the said steps:
Try this. I hope it helps.
And finally, If you've followed all the steps here and are at your wit's end...make sure the file that you're running (the one with your source code in it ya know), isn't named object_detection.py - that would preclude it being searched for as a module.
Certainly I've never done anything like this that led me to add an embarrassing answer on Stack Overflow...
I had to do:
sudo pip3 install -e . (ref)
sudo python3 setup.py install
System:
OS: Ubuntu 16.04, Anaconda (I guess this is why I need to use pip3 and python3 even I made virtual environment with Pyehon 3.8)

ImportError: No module named stack

I have a code in python that I have been working on and it builds and runs very well on my pc (Windows). I had to run the same code on my other machine which runs ubuntu,so I had to install all the packages on prior to runing the code. The problem is I ran into this error which I couldn't figure out. The error is triggered by one of the installed packages.
from qalsadi import analex
File "/usr/local/lib/python2.7/dist-packages/qalsadi/analex.py", line 14, in <module>
import pyarabic.araby as araby # basic arabic text functions
File "/usr/local/lib/python2.7/dist-packages/pyarabic/araby.py", line 28, in <module>
from stack import *
ImportError: No module named stack
I used the following command, "sudo pip install pyarabic", to install it. However, still the file stack.py doesn't exist among it's files. I searched in the folder /usr/local/lib/python2.7/dist-packages/pyarabic. The folder contains the following: araby.py and init.py and the coresponding pyc files only. I'v insalled and uninstalled it a number of times using "pip" but still the file is not there.
Check your pyarabic folder. Usually it's in Python27\Lib\site-packages\pyarabic.
There, there should be stack.py. If it doesn't exists, re-download pyarabic and then reinstall it.
After installation of pyarabic import STACK in this manner:
from pyarabic.stack import Stack
for window users
open cmd prompt and type the following to install the stack variable to python 3.x-
pip install pyarabic
To install and run with this code-
from pyarabic.stack import Stack
It seems like stack is not part of the Python Package Index so most probably it is a script you installed manually. The problem can be that the folder containing stack.py is not on your PYTHONPATH.
Open a terminal (Ctrl+ Alt + t) and edit the .bashrc file:
sudo gedit ~/.bashrc
Add the following line:
export PYTHONPATH=$PYTHONPATH:/path/to/the/folder/of/your/module
where you should substitute the part after the : to the full path to the directory
where stack.py can be found.
I hope this helps.

Categories