1

New to QGIS and Python. Have QGIS installed and working great on Windows, want to install and use Docutils -- Python Documentation Utilities (presumably all simple and small .py programs).

I see that QGIS has a Python Console built in. Do I just use that? What is the command line to run install.py?

QGIS obviously installed Python. However it looks like the customary path variables were not set during the QIS install, such that Python can be run from a windows command (cmd.exe) window.

That seems to be the task here, so I proceed to try to enable Python to run independent of QGIS.

First I search for python.exe. I find it at: C:\Program Files\QGIS Lyon\bin

So I set the windows path variable to include that.

After searching (and a lot of confusion as to where the Python distribution actually is, is it standard, or is it custom, questions as to how libraries, etc are laid out, and noting its all installed "underneath" C:\Program Files\QGIS Lyon) so it appears custom(?) Will I break that by using it for "generalized" Python programs?

I try the following environmental values:

PYTHONPATH C:\Program Files\QGIS Lyon\apps\Python27\Lib

PYTHONHOME C:\Program Files\QGIS Lyon\bin

Have no idea if those are even close to correct. I then run the install for docutils

C:\Users\rick\Desktop\docutils-0.12>python install.py

Program starts, but then errors per below.

Seems like a "documentation utility" should be a snap to install. Plus there probably a straightforward way to run Python programs independent of QGIS? I also note an additional install of Python with Inkscape (a vector drawing program used in the QGIS training manual.) So already two installs of Python on the system already. (Correction, three installs. FWTools has yet another Python install.)

If a user wants to run Python programs (such as docutils and other small learning programs) should they download a fresh Python "stand alone" install? (looks like on this machine that would be the 4th install?)


errors

C:\Users\rick\Desktop\docutils-0.12>python install.py

This is a quick & dirty installation shortcut. It is equivalent to the command::

python setup.py install

However, the shortcut lacks error checking and command-line option processing. If you need any kind of customization or help, please use one of::

python setup.py install --help
python setup.py --help

Traceback (most recent call last): File "install.py", line 27, in dist.run_commands() File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\dist.py", line 95 3, in run_commands self.run_command(cmd) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\dist.py", line 97 2, in run_command cmd_obj.run() File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\command\install.p y", line 575, in run self.run_command(cmd_name) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\cmd.py", line 326 , in run_command self.distribution.run_command(command) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\dist.py", line 97 2, in run_command cmd_obj.run() File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\command\install_l ib.py", line 97, in run outfiles = self.install() File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\command\install_l ib.py", line 115, in install outfiles = self.copy_tree(self.build_dir, self.install_dir) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\cmd.py", line 377 , in copy_tree dry_run=self.dry_run) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\dir_util.py", lin e 139, in copy_tree mkpath(dst, verbose=verbose) File "C:\Program Files\QGIS Lyon\apps\Python27\Lib\distutils\dir_util.py", lin e 76, in mkpath "could not create '%s': %s" % (head, exc.args[-1])) distutils.errors.DistutilsFileError: could not create 'C:\Program Files\QGIS Lyo n\bin\Lib': Access is denied

1

Don't make life more complicated, it's much easier:

  • On Unix systems (Linux and Mac OS X) QGIS use the standard Python, installed by default. This is not the case in Windows where Python is not installed by default and there is no PYTHONPATH variable.
  • Therefore QGIS installs its own version (with libraries in C:\Program Files\QGIS Lyon\apps\Python27 in the Standalone version and a different location in the OSGeo4W installer)

So:

1) You can use the Python console as a classic Python shell using exclusively the QGIS Python with PyQGIS and the other modules installed by default, as Numpy (in C:\Program Files\QGIS Lyon\apps\Python27\Lib\site-packages) = the PYTHONPATH of the QGIS Python. You can control it by typing in the console

import sys
print sys.path

2) if you want to install an other Python module as Docutils, the problem is that Setuptools (setup.py, easy_install) or pip are not installed by default, even with the OSGeo4W installer, -> look at How to install 3rd party python libraries for QGIS on Windows?, QGIS Standalone and the Python Modules, Installing Python setuptools into OSGeo4W Python or OSGeo4W External Python Packages

At this stage, you have a full Windows Python version: you can use setup.py, easy_install or pip to install new modules, you don't need to fix the PYTHONPATH and you can use PyQGIS and the other modules installed in the QGIS site_packages folder

  1. via commands in the Python console
  2. via Python scripts in the Processing Toolbox or with the ScritRunner plugin of Gary Sherman
  3. via the development of custom Plugins

If you want to use other simple modules installed in other Python versions, simply use:

sys.path.append(path_of_the_module)

3) But if you want to use PyQGIS from outside (in other version of Python), it is another problem: search for on the GIS SE or the Web (as in Configure PyScripter to use with QGIS (and still use arcpy) on Windows, Standalone applications using QGIS and environment variables, and many others)

  • Thanks very much for the detailed response. Top two bullets are very well understood. The balance I struggle a bit with. I'm starting with a remove and replace QGIS with the QGIS osgeo4w distribution. Since I need to run Docutils option 1 appears ruled out. No immediate need to call PyQGIS from an outside version of Python so that rules out option 3. Will be looking to add that Setuptools or pip following your links in #2, and from there Docutils. Is Windows a difficult platform for QGIS? Is Unix much better suited? I have some Unix background but honestly, ts been quite a while... – rjlabs Feb 19 '16 at 1:11
  • Took a while for the Remove/Replace QGIS above, but worked. Used curl (installed by default with osgeo4w distribution) to get pip, and then pip to get docutils following directions on this page: trac.osgeo.org/osgeo4w/wiki/ExternalPythonPackages. Docutils runs fine. Whole process seems a lot like Perl. (reminds me of a Spamassassin install on single user Unix). Thanks again. – rjlabs Feb 19 '16 at 3:56
  • " Is Windows a difficult platform for QGIS? Is Unix much better suited?": for me yes, because Unix use the internal Python installed by default and it is very easy to add new modules without having to worry about QGIS – gene Feb 19 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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