Beispiel #1
0
/**
 * Returns the complete python version
 * eg 2.7.9
 * Make sure to have setup python first
 */
QString Utils::Misc::pythonVersionComplete()
{
    static QString version;
    if (version.isEmpty()) {
        if (pythonExecutable().isEmpty())
            return version;
        QProcess pythonProc;
        pythonProc.start(pythonExecutable(), QStringList() << "--version", QIODevice::ReadOnly);
        if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) {
            QByteArray output = pythonProc.readAllStandardOutput();
            if (output.isEmpty())
                output = pythonProc.readAllStandardError();

            // Software 'Anaconda' installs its own python interpreter
            // and `python --version` returns a string like this:
            // `Python 3.4.3 :: Anaconda 2.3.0 (64-bit)`
            const QList<QByteArray> verSplit = output.split(' ');
            if (verSplit.size() > 1) {
                version = verSplit.at(1).trimmed();
                Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(version), Log::INFO);
            }
        }
    }
    return version;
}
Beispiel #2
0
Python::Python()
{
#ifdef Q_OS_WIN
	// This code finds the python directory, which doesn't really have a standard naming convention
	QDir pythonInstall("C:/");
	QStringList pythons = pythonInstall.entryList(QStringList() << "Python*", QDir::NoDotAndDotDot | QDir::Dirs);
	if(pythons.size() > 0) pythonInstall.cd(pythons[0]);
	m_pythonPath = pythonInstall.filePath("python.exe");
#else
	m_pythonPath="/usr/bin/python";
#endif

	QFileInfo pythonExecutable(m_pythonPath);
	if(!pythonExecutable.exists()) QMessageBox::critical(0, "Error", "Could not find Python Executable!");

	m_python.setReadChannel(QProcess::StandardError);

}