File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -1680,6 +1680,20 @@ void PythonQt::overwriteSysPath(const QStringList& paths)
16801680void PythonQt::setModuleImportPath (PyObject* module , const QStringList& paths)
16811681{
16821682 PyModule_AddObject (module , " __path__" , PythonQtConv::QStringListToPyList (paths));
1683+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
1684+ // Since Python 3.4 a module has a __spec__ member of type ModuleSpec which
1685+ // mirrors some module-specific attributes, see
1686+ // https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec .
1687+ //
1688+ // Python 3.9 prints an import warning "__package__ != __spec__.parent" on relative imports
1689+ // if we don't set the submodule_search_locations on __spec__ (this indirectly changes
1690+ // the value of parent)
1691+ PyObject* spec = PyObject_GetAttrString (module , " __spec__" );
1692+ if (spec) {
1693+ PythonQt::self ()->addVariable (spec, " submodule_search_locations" , paths);
1694+ Py_DECREF (spec);
1695+ }
1696+ #endif
16831697}
16841698
16851699void PythonQt::stdOutRedirectCB (const QString& str)
You can’t perform that action at this time.
0 commit comments