ptwobrussell / Mining-the-Social-Web

The official online compendium for Mining the Social Web (O'Reilly, 2011)
http://bit.ly/135dHfs
Other
1.21k stars 491 forks source link

IFrame not found in IPython.display Example 7-17(2nd Edition) #70

Closed dlunga closed 10 years ago

dlunga commented 10 years ago

Hi Matt,

I have two issues all related to example 7-17:

1) In following your example 7-17 and I appear to be running into this error:

from IPython.display import IFrame Traceback (most recent call last): File "", line 1, in ImportError: cannot import name IFrame

2) where can I find the D3 template for displaying the graph data in the same example line viz_file ='files/resources/ch07-github/force.html'

I could not find any template named force.html from the files I downloaded from github.

Any ideas why this is happening?

Thanks,

ptwobrussell commented 10 years ago

@dlunga - Thanks for reaching out. I'll do everything that I can to help you get through this as quickly as possible.

0) - Are you working from a "git clone" of the repository or are you copying/pasting code? Using the virtual machine or using an IPython Notebook installation of your own? Just want to make sure you're aware of this screencast just in case... https://vimeo.com/channels/MiningTheSocialWeb If you aren't working with the benefit of the virtual machine, I'd highly recommend it.

My responses below assume that you are working from the VM...

1) - This is peculiar. I just double checked, and the code that is currently checked in is working for me, and I don't recall having this kind of error before. Can you create a new cell in IPython Notebook and run this code?

import IPython
print IPython.__version__

I'm curious if you're getting back "1.0.0" as the result, which is the latest that's been checked in for the Vagrant configuration. Even if you are using your own IPython Notebook, however, I think IFrame has been around for a very long time, so you'd have to be using quite an old version for this not to import. Let's start here and see where we get...

2) - The template is at ipynb/resources/ch07-github/force.html if you are working from a source code checkout where you have done a "git clone" on the repository. e.g. here: https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition/tree/master/ipynb/resources/ch07-github

Let me know if this helps...I'd like for you to have an enjoyable experience. (Chapter 7 is one of my favorite chapters!)

dlunga commented 10 years ago

Wow - what a speedy response! Impressive. Here are my responses:

I am working from a IPython Notebook of my own installation. I picked up that the installation that comes with Anaconda is based on an old version of IPython. I have since updated it to IPython 1.0.0 and the result is positive - it works.

On the second issue, I had simply downloaded the zip file with "all" the code (not the "git clone" option). I will try that or make use of the link you provided.

I agree chapter 7 is fascinating.

Thank you so much.

Great Book, Great Code, Great Support

dlunga commented 10 years ago

Hello Matt,

With all my earlier issues cleared up - I am running into this error (still on Example 7-17): CODE: gr = json_graph.node_link_data(g) json.dump(gr,open('filename.json','w')) viz_file ='filename.html' #after renaming the force.html template you refer too in the book) display(IFrame(viz_file,'100%','600px'))

ERROR: Traceback (most recent call last): File "", line 10, in File "C:\Anaconda\lib\site-packages\IPython\core\display.py", line 116, in display format = InteractiveShell.instance().display_formatter.format File "C:\Anaconda\lib\site-packages\IPython\config\configurable.py", line 349, in instance inst = cls(_args, *_kwargs) File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 473, in init self.init_readline() File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 1849, in init_readline self.refill_readline_hist() File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 1858, in refill_readline_hist stdin_encoding = sys.stdin.encoding or "utf-8" AttributeError: PseudoFile instance has no attribute 'encoding'

It seems to require an encoding of some sort! Any ideas on this are much appreciated.

Thanks. D.

ptwobrussell commented 10 years ago

Really glad to hear that you're over those hurdles. Let's figure out what's going on now. (Sorry you are having these issues, and FWIW, this is exactly what I created the VM - so that everyone will be be able to work on a known environment that I've vetted and works as-is as opposed to trying to diagnose problems across many platforms and versions of software. I'd encourage you to check it out.)

I can't quite tell from your stack trace, but just to double check: are you trying to run display(IFrame(viz_file,'100%','600px')) from within an IPython interpreter or from within IPython Notebook? I'm assuming the latter (still), but just wanted to double check since the stack suggests that you may be working through the interactive shell. Let me know, and we can work forward from there...

dlunga commented 10 years ago

Hello Matt,

Thanks for getting back to me. I am running display(IFrame(viz_file,'100%','600px')) from within an IPython interpreter that comes within the Anaconda installation (not sure if mentioning this will help).

Any ideas?

ptwobrussell commented 10 years ago

I may be wrong (never used Anaconda myself but probably will try it out soon so as to be more familiar with advising folks), but I'm not sure that you can use display(IFrame(...)) from within any kind of interpreter, whether it be Anaconda or anything else. AFAIK, these functions are used exclusively within IPython Notebook to take advantage of the web browser's ability to display web content.

To that end, I would recommend either trying out IPython Notebook via the virtual machine, which should be trivial for you to get up and running (recommended) or simply opening the html file yourself to render the visualization (less recommended but should still work fine.)

In order to run with the VM, just follow along with the screencast I linked above.

In order to open the filename.html file yourself, you may have to fiddle with your browser's settings to allow it to load D3 as an external library when trying to render local data, but it should work nonetheless after you find the right settings, which would probably be tucked away under "security" somewhere. (I could help you locate them if you tell me your browser, though I don't have access to IE right at this moment.)

You could also navigate to the directory containing the HTML page in a terminal (Command Prompt on Windows) and serve anything in the directory with this command: python -m SimpleHTTPServer after which you could navigate to http://localhost:5000/filename.html (or whatever port/filename combination you need.)

Does that help you get into a position to move forward?

dlunga commented 10 years ago

Thanks Matt. Let me try the virtual machine option - it maybe wise doing so now. Thanks for all your help. I will go ahead and close this call.