qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
26.86k stars 3.87k forks source link

Fails to discover Python installation on Windows #14721

Closed johnnyschneider closed 3 weeks ago

johnnyschneider commented 3 years ago

Please provide the following information

qBittorrent version and Operating System

qBittorrent 4.3.4.1, Windows 10 (20H2) 10.0.19042

If on linux, libtorrent-rasterbar and Qt version

N/A

What is the problem

qBittorrent does not discover Python provided that Python is installed via pyenv-win on Windows. I know this, because the search engine refuses to discover Python and prompts me to install it, never mind the fact that python --version returns Python 3.9.1 in the terminal.

What is the expected behavior

Search engine opens up automatically, without issue.

Steps to reproduce

Install Python via pyenv-win on Windows, and then install qBittorrent 4.3.4.1, and attempt to use the search engine.

Extra info(if any)

Not a new bug. This issue has been around for as long as I've been using pyenv-win.

johnnyschneider commented 3 years ago

Hi, have done some research. The python issues do not show up in the MinGW build system, because it uses dynamic linkage. This issue requires testing static linkage.... I have been struggling with some build issues for Windows using static linkage (see: https://github.com/microsoft/vcpkg/issues/18086). As such, I cannot submit PR's, as I cannot build local changes to test any code diffs. That said, I've done a fair bit of research.... src/base/utils/foreignapps.cpp's testPythonInstallation() almost certainly is not functioning necessarily properly, because I can only assume that based on the name of the function, it should properly return the location of a Python installation if it exists.... I believe the issue has something to do with the attempt to clip unnecessary values that may exist in the Python installation version string.

see: in src/base/utils/foreignapps.cpp:72

const QString versionStr = outputSplit[1];
const int idx = versionStr.indexOf(QRegularExpression("[^\\.\\d]"));

try
{
      info = {exeName, versionStr.left(idx)};
}

To any maintainers who are not immediately familiar with the code and can test the changes for me, here is some context:

In the preceding code, outputSplit[1] returns the second whitespace-terminated string in a python version statement (outputSplit[0] would return the string "Python") - this should in virtually all instances of any Python distro, contain the numbering scheme, e.g. "1.2.3" . If you test the regex from line 73 provided in Regexr, that regex is essentially looking for almost any non-alphanumeric character encapsulated within quotes. For example, the strings (including quotes) "+", "=", "~" pass. I believe Qt's regex code strips the quotes. Thus, if and only if this character is present in the aforementioned numbering scheme string , the .indexOf() line will return the index of that character. Of course, if it is not present, standard practice is to return -1 for any function like this and I can only assume this Qt method does the same. Unfortunately, as noted by the comments above this block of code, this character may only be present in Anaconda installations, I guess. Coding the testPythonInstallation() method against Anaconda testing is certainly important, but to default to Anaconda is problematic. I suggest adding a line that tests if idx == -1 then simply passing the correct versionStr into info.

if (idx == -1) {
      try {
            info = {exeName, versionStr}
      }
} else {
      try {
            info = {exeName, versionStr.left(idx)};
      }
}

That said, the backup methods of finding Python installations were not working either. Those centered around looking in the registry, and worst case scenario, looking at the usual install paths. I discovered that pyenv-win does not modify the registry values. This is a minor feature that the stock windows Python installation system provides, and that ideally pyenv-win should, but alas, does not yet. This is not an issue with qBittorrent, and I will look into addressing it with that project. As it stands, I can demonstrate manual modifications of the Windows registry, point the keys to a Python installation, and observe qBittorrent correctly detect the installation. As such, consider that aspect of my bug report closed. Please do not close the entire bug report, though, until the above code, or some similar testing, has passed.

Cordially, Johnny

8wx commented 3 years ago

I installed python via Microsoft Store (one of the recommended method by the official guide), and qBittorrent doesn't recognize it. python and python3 commands are working properly though.

drvictorvs commented 1 year ago

I also want to report that qBittorrent fails to recognize Python installations done through Microsoft Store, which is one of the few ways to properly install Python if you don't have administrator access. Then it requests to install an older version of Python. This is, at best, going to lead to people without administrator access to have to use another tool (since you can't create that key either), and at worst, introduce vulnerabilities by having multiple Python installations. Why don't you just look at the path environmental variable?

xavier2k6 commented 3 weeks ago

qBittorrent 4.3.4.1

Version is obsolete.

Thank you for your contribution, we are starting to close all old/stale/obsolete tickets.

Please update to latest qBittorrent 4.6.5 ATTOW.

If any issues are experienced, please open a new ticket.

qBittorrent 5.0 will have an option for user to select/define location of python.