Posts Tagged ‘social networks’

Python and NetworkX

Posted: December 14, 2009 in Networks
Tags: , , ,

I have been trying to use the NetworkX Python package in my work with Social Networks. But I faced some confusion in trying to link it to my Python Interpreter. Finally, I have found a solution [:)] after hours of mind racking. The following steps may be followed:

1:      If you do not already have Python in your system [:-o], download it from here. If you already have Python, proceed to the next step.

For those who are sceptical about using Python, should take a break and visit this link. Seriously though, Python provides a much simpler code structure, and does not scare off starters. First timers will realise the joy of programming using Python. And particularly for working in Networks and Graphs, Python has this NetworkX library, which is very clean and free from all those lines of code. Of course, one can also work in C++ or for that matter, JAVA. But python provides you with the freedom and very less headache!

2:     Now once you have installed python in your system, you need to download NetworkX package from here. Note that you are NOT to use the .egg file, rather take the latest version zip file or .tar.gz

3:     I assume that you have WinZip(or any other unzipping facility). Extract your zip(or .tar.gz.) file using that. Open the folder to find a folder named “networkx”. Copy this folder to your Python directory (e.g. C:\python\). You can also install networkx in your system. If you want to do so, read up the INSTALL.txt file(also in the .zip folder) and follow the provided instructions. I personally found the former quite an easier and hassle free way to integrate NetworkX in Python, but you are welcome to learn it the harder(and dirtier) way.

4:     Next and the last step is to start  your Python Interactive interpreter and type the following at the prompt:

>>>import networkx as nx

and press ENTER. If you get

>>>import networkx as nx

>>>

then you are done. Congrats !!

If  however you get some error regarding module does not exist, then you need to review your steps in integrating NetworkX. Start over and carefully check each step. With some luck, you will succeed.

Happy Networking!! 😀