@@ -58,18 +58,31 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
58
58
runString ( " import sys" ); // import sys module (for display / exception hooks)
59
59
runString ( " import os" ); // import os module (for user paths)
60
60
61
+ #ifdef Q_OS_WIN
62
+ runString ( " oldhome=None" );
63
+ runString ( " if os.environ.has_key('HOME'): oldhome=os.environ['HOME']" );
64
+ runString ( " os.environ['HOME']=os.environ['USERPROFILE']" );
65
+ #endif
66
+
61
67
// construct a list of plugin paths
62
68
// plugin dirs passed in QGIS_PLUGINPATH env. variable have highest priority (usually empty)
63
69
// locally installed plugins have priority over the system plugins
64
- QStringList pluginpaths = extraPluginsPaths ();
65
- pluginpaths << homePluginsPath () << pluginsPath ();
70
+ // use os.path.expanduser to support usernames with special characters (see #2512)
71
+ QStringList pluginpaths;
72
+ foreach ( QString p, extraPluginsPaths () )
73
+ {
74
+ pluginpaths << ' "' + p + ' "' ;
75
+ }
76
+ pluginpaths << " os.path.expanduser(\" ~/.qgis/python/plugins\" )" ;
77
+ pluginpaths << ' "' + pluginsPath () + ' "' ;
66
78
67
79
// expect that bindings are installed locally, so add the path to modules
68
80
// also add path to plugins
69
81
QStringList newpaths;
70
- newpaths << pythonPath () << homePythonPath ();
71
- newpaths += pluginpaths;
72
- runString ( " sys.path = [\" " + newpaths.join ( " \" , \" " ) + " \" ] + sys.path" );
82
+ newpaths << ' "' + pythonPath () + ' "' ;
83
+ newpaths << " os.path.expanduser(\" ~/.qgis/python\" )" ;
84
+ newpaths << pluginpaths;
85
+ runString ( " sys.path = [" + newpaths.join ( " ," ) + " ] + sys.path" );
73
86
74
87
// import SIP
75
88
if ( !runString ( " from sip import wrapinstance, unwrapinstance" ,
@@ -104,7 +117,11 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
104
117
}
105
118
106
119
// tell the utils script where to look for the plugins
107
- runString ( " qgis.utils.plugin_paths = [\" " + pluginpaths.join ( " \" ,\" " ) + " \" ]" );
120
+ runString ( " qgis.utils.plugin_paths = [" + pluginpaths.join ( " ," ) + " ]" );
121
+
122
+ #ifdef Q_OS_WIN
123
+ runString ( " if oldhome: os.environ['HOME']=oldhome" );
124
+ #endif
108
125
109
126
// initialize 'iface' object
110
127
runString ( " qgis.utils.initInterface(" + QString::number (( unsigned long ) interface ) + " )" );
0 commit comments