Why can’t PySpark find py4j.java_gateway?

In my environment (using docker and the image sequenceiq/spark:1.1.0-ubuntu), I ran in to this. If you look at the pyspark shell script, you’ll see that you need a few things added to your PYTHONPATH: export PYTHONPATH=$SPARK_HOME/python/:$PYTHONPATH export PYTHONPATH=$SPARK_HOME/python/lib/py4j-0.8.2.1-src.zip:$PYTHONPATH That worked in ipython for me. Update: as noted in the comments, the name of the py4j … Read more

How to call module written with argparse in iPython notebook

An alternative to use argparse in Ipython notebooks is passing a string to: args = parser.parse_args() (line 303 from the git repo you referenced.) Would be something like: parser = argparse.ArgumentParser( description=’Searching longest common substring. ‘ ‘Uses Ukkonen\’s suffix tree algorithm and generalized suffix tree. ‘ ‘Written by Ilya Stepanov (c) 2013’) parser.add_argument( ‘strings’, metavar=”STRING”, … Read more

Launch IPython notebook with selected browser

I had the same problem on windows and got it work this way: Create a config file with command ipython profile create default Edit ipython_notebook_config.py file, search for line #c.NotebookApp.browser=”” and replace it with import webbrowser webbrowser.register(‘firefox’, None, webbrowser.GenericBrowser(‘C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe’)) c.NotebookApp.browser=”firefox” then it works for me. Hope it will help you. JPG

import a function from another .ipynb file

You’ll want to use the ipynb package/module importer. You’ll need to install it: pip install ipynb. Create a Notebook named my_functions.ipynb. Add a simple function to it. def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) Then, create a second IPython Notebook and import this function with: from ipynb.fs.full.my_functions import factorial … Read more

how to reload a Class in python shell?

On Python 3 only, import the reload function: >>> from importlib import reload On both Python 2.x, and 3.x, you can then simply call reload on the module: >>> import MyPak >>> reload(MyPak) >>> from MyPak import MyMod However, instances of the old class will not be updated (there’s simply no code that describes the … Read more

How do I set up Jupyter/IPython Notebook for Django?

Install django-extensions from https://github.com/django-extensions/django-extensions/blob/master/docs/index.rst pip install django-extensions Change your settings file to include ‘django-extensions’ INSTALLED_APPS += [‘django_extensions’] Run your Django server like this: python manage.py shell_plus –notebook alter to suit, and run this in your first cell import os, sys PWD = os.getenv(‘PWD’) os.chdir(PWD) sys.path.insert(0, os.getenv(‘PWD’)) os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “local_settings.py”) import django django.setup() Now you should be … Read more