5

How to install and how to compile networkx python on QGIS?

I always get an error that no module named networkx in the console of QGIS.

I copied the file networkx in C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages and there are not change.

2
  • 1
    Welcome to gis.stackexchange. Could you explain how you are trying to install it? Did you follow the documentation e.g. networkx.github.com/documentation/latest/… ?
    – steko
    Feb 23, 2013 at 20:22
  • i am trying to install networkx Python library in QGIS after i installed it,in order to Analyze spatial graphs in QGIS with Python
    – user15484
    Feb 23, 2013 at 20:58

2 Answers 2

5

I copied the file networkx

It is not a simple file, it is a folder with many files. You must place the entire unzipped networkx folder in C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages (because it is a simple module)

In general, to use a Python module, you must first install it:

python setup.py install

As on Windows, QGIS uses its own version of Python (not in the Windows's registry), without a Python shell, you can:

  1. use the bootstrapped installer for setuptools of Nathan's QGIS Blog, which will install directly the module into a folder rather than looking in the registry
  2. download the networkx version of Christoph Gohlke at Unofficial Windows Binaries for Python Extension Packages, unzip it (it is a .exe file but you can directly unzip it) and place the resulting folder in C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages.

After that, in the Python console of QGIS:

import networkx
networkx.__file__
'C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages\networkx\__init__.pyc'

or

'C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages\networkx-1.7-py2.7.egg\networkx\__init__.pyc'

depending on how you installed the module

5
  • thank you bro for your help,but i did installed python on QGIS and i did place networkx on "C:\Program Files\Quantum GIS Lisboa\apps\Python27\Lib\site-packages" but nothing happend the same mistake,always after i opened QGIS and open console python and i call networkx "import networkx " it's says that no module named networkx,
    – user15484
    Feb 24, 2013 at 10:44
  • never mind,i fond the problem,its in networkx i palced it but hte hole file it must palce the Content of the file networkx in the site packages,htank you again my friend
    – user15484
    Feb 24, 2013 at 10:59
  • @gene I tried the second solution and it worked. Thanks A LOT!
    – Alex
    Apr 27, 2014 at 13:54
  • @gene I've tried to do what you said but have an ImportError: No module named decorator
    – user25976
    Apr 7, 2015 at 21:50
  • install the decorator module
    – gene
    Apr 8, 2015 at 16:36
4

The easiest way to install networkx python module to run it from QGIS is to use OSGeo4W installer. It will handle all the dependencies that networkx rely on.

Download OSGeo4W Network installer from QGIS download page, then right-click the EXE file and select Run as Administrator, select Advance install and follow the steps until you find the following window:

enter image description here

In the Search box write networkx and you will have two versions located under Libs: one for python 2 and the other for python 3. Choose networkx for python 2 because this what is currently used in QGIS 2.X.X and click on Next to install. In the image above it is written Keep because it is already installed, but for the first time installation you have to click Install.

When the installation finishes successfully, you can import networkx module directly from inside QGIS Python Console, and it will not give an import error.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.