17
17
#include < QtCore/QVariant>
18
18
19
19
#include < string_view>
20
+ #include < utility>
20
21
21
22
using namespace Qt ::StringLiterals;
22
23
@@ -123,26 +124,29 @@ static bool runPyScriptFile(const QString &fileName, QString *errorMessage)
123
124
return ok;
124
125
}
125
126
127
+ static std::pair<int , int > pythonVersion ()
128
+ {
129
+ // read environment set by pyside_tool.py
130
+ bool majorOk{};
131
+ bool minorOk{};
132
+ const int majorVersion = qEnvironmentVariableIntValue (" PY_MAJOR_VERSION" , &majorOk);
133
+ const int minorVersion = qEnvironmentVariableIntValue (" PY_MINOR_VERSION" , &minorOk);
134
+ if (majorOk && minorVersion)
135
+ return {majorVersion, minorVersion};
136
+ return {PY_MAJOR_VERSION, PY_MINOR_VERSION};
137
+ }
138
+
126
139
static void initVirtualEnvironment ()
127
140
{
128
141
static const char virtualEnvVar[] = " VIRTUAL_ENV" ;
129
- // As of Python 3.8/ Windows, Python is no longer able to run stand-alone in
130
- // a virtualenv due to missing libraries. Add the path to the modules
131
- // instead. macOS seems to be showing the same issues.
142
+ // Since Python 3.8 ( Windows, macOS), Python is no longer able to run stand
143
+ // -alone in a virtualenv due to missing libraries. Add the path to the modules
144
+ // instead.
132
145
133
146
const auto os = QOperatingSystemVersion::currentType ();
134
147
135
- bool ok;
136
- int majorVersion = qEnvironmentVariableIntValue (" PY_MAJOR_VERSION" , &ok);
137
- int minorVersion = qEnvironmentVariableIntValue (" PY_MINOR_VERSION" , &ok);
138
- if (!ok) {
139
- majorVersion = PY_MAJOR_VERSION;
140
- minorVersion = PY_MINOR_VERSION;
141
- }
142
-
143
148
if (!qEnvironmentVariableIsSet (virtualEnvVar)
144
- || (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)
145
- || (majorVersion == 3 && minorVersion < 8 )) {
149
+ || (os != QOperatingSystemVersion::MacOS && os != QOperatingSystemVersion::Windows)) {
146
150
return ;
147
151
}
148
152
@@ -155,11 +159,13 @@ static void initVirtualEnvironment()
155
159
case QOperatingSystemVersion::Windows:
156
160
pythonPath.append (virtualEnvPath + R"( \Lib\site-packages)" );
157
161
break ;
158
- case QOperatingSystemVersion::MacOS:
162
+ case QOperatingSystemVersion::MacOS: {
163
+ const auto version = pythonVersion ();
159
164
pythonPath.append (virtualEnvPath + " /lib/python" _ba +
160
- QByteArray::number (majorVersion ) + ' .'
161
- + QByteArray::number (minorVersion )
165
+ QByteArray::number (version. first ) + ' .'
166
+ + QByteArray::number (version. second )
162
167
+ " /site-packages" _ba);
168
+ }
163
169
break ;
164
170
default :
165
171
break ;
0 commit comments