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 @@ -1690,6 +1690,20 @@ void PythonQt::overwriteSysPath(const QStringList& paths)
16901690void PythonQt::setModuleImportPath (PyObject* module , const QStringList& paths)
16911691{
16921692 PyModule_AddObject (module , " __path__" , PythonQtConv::QStringListToPyList (paths));
1693+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
1694+ // Since Python 3.4 a module has a __spec__ member of type ModuleSpec which
1695+ // mirrors some module-specific attributes, see
1696+ // https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec .
1697+ //
1698+ // Python 3.9 prints an import warning "__package__ != __spec__.parent" on relative imports
1699+ // if we don't set the submodule_search_locations on __spec__ (this indirectly changes
1700+ // the value of parent)
1701+ PyObject* spec = PyObject_GetAttrString (module , " __spec__" );
1702+ if (spec) {
1703+ PythonQt::self ()->addVariable (spec, " submodule_search_locations" , paths);
1704+ Py_DECREF (spec);
1705+ }
1706+ #endif
16931707}
16941708
16951709void PythonQt::stdOutRedirectCB (const QString& str)
You can’t perform that action at this time.
0 commit comments