Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am currently working on a QGIS plugin which depits node to node discreet flows. Let' say adaption of Tobler's Flow Mapper to QGIS.

Plugin currently tested and working under Windows. But not under Linux or MacOS X.

As far as I can figure, this is due to a path problem where user chooses the output shapefile location.

Here is what code look likes:

def OutputShp(self):
    dlg = FlowMapperDialog()
    fd = QtGui.QFileDialog(dlg)
    global SaveShpName
    global SaveShpDirectory
    SaveShpName = fd.getSaveFileName(None, 'Shapefile(*.shp)', 'Type output shapefile name', '*.shp')
...some code...

SaveDirectory = os.path.realpath(SaveShpName)
flowpyv07.shapefilemaker(FlowType,str(SaveDirectory), str(SaveShpName),str(InputMatrixName),str(InputNodesName),str(combotext))

When I run it I get the following error:

Traceback (most recent call last):

File "/home/user/.qgis//python/plugins/FlowMapper/flowmapper.py", line 1346, in run

SaveDirectory = os.path.realpath(SaveShpName)

File "/usr/lib/python2.7/posixpath.py", line 358, in realpath if isabs(filename):

File "/usr/lib/python2.7/posixpath.py", line 53, in isabs return s.startswith('/')

AttributeError: 'QString' object has no attribute 'startswith'

Python version: 2.7.3 (default, Aug 1 2012, 05:27:35) [GCC 4.6.3]

QGIS version: 1.8.0-Lisboa Lisboa, exported

However, if I enter the "SaveDirectory" path manually in the code such as "/home/user/Documents/" it works like charm. Thus I think I cannot get the path correctly. Any suggestion is valuable since users regret if it does not work under Linux.

If needed, full source code and plugin is avaliable from the QGIS repo: http://plugins.qgis.org/plugins/FlowMapper/

share|improve this question
add comment

1 Answer

The Problem might be that Linux/Mac systems have a different file separator as Windows. You can print the system specific separator like this

from os import path
print path.sep 
> "/"

Therefore you have to concatenate your path elements depending on the users system. For instance like this:

import os
myhost = os.uname()[0]
if myhost == "Linux":

It might be a good idea to print out the SaveDirectory-variable on every system to see how it looks like.

Good look with your plugin ;)

share|improve this answer
You should really just use os.path.join and it will do it for you. –  Nathan W Jun 3 '13 at 21:07
Thanks for valuable help. os.path.realpath(SaveShpName) returns c:\filename.shp while SaveShpName returns c:/filename.shp Just deleted os.path.realpath and now works under both Linux and Windows –  cempro Jun 3 '13 at 23:29
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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