MT5 Python initialize() hangs: terminal build mismatch
Your script calls mt5.initialize() and never gets past it. An MQL5 forum thread traced one case to two MetaTrader 5 builds that did not match, and installing the broker's build fixed it. What that thread says, what MetaQuotes says about the oldest build that still connects, and what to check, each read on 30 November 2026.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
Steps
The thread: build 5233 from the developer's site, build 5238 from the broker
On the MQL5 forum on 31 August 2025 a user reported that the Python process froze at mt5.initialize() and never reached the line after it, while the terminal itself opened normally; the terminal was 5.00 build 5233 and admin rights, a second shell and the environment file had already been checked. A reply the same day suggested confirming that both Python and the terminal were 64 bit. On 1 September 2025 the original poster confirmed both were 64 bit, that downgrading Python to 3.10 made no difference, and that the cause was a mismatch between the build downloaded from the developer's website and the one their broker supplies: installing the broker's build 5238 resolved the freeze. The thread gives those two numbers and no general rule.
mql5.comchecked
Check which terminal your script starts, and its build
In each MetaTrader 5 terminal installed on the machine, open Help, then About, and note the build. If more than one terminal is installed, pass the full path of the one you mean to initialize(path=...), so there is no doubt which copy the package connects to. The package reaches the terminal over interprocess communication on the same machine, which is why a hang rather than an error is possible: the two sides have to agree before initialize() can return anything. These checks follow from the thread above; they are not steps anyone on it reported as fixes.
mql5.comchecked
The oldest build that still connects: 4755
MetaQuotes announced on 12 May 2025 that support for older versions of MetaTrader 4 and MetaTrader 5 would end on 1 July 2025, that the minimum supported MetaTrader 5 build is 4755, released on 13 December 2024, and that after that date older desktop terminals will no longer be able to connect to broker servers. A terminal below that build has a problem before Python is involved.
metaquotes.netchecked
Check the package version too
pip show MetaTrader5 prints the installed version. The newest release on PyPI on 30 November 2026 was 5.0.6231, published 27 September 2026, as Windows x86-64 wheels for CPython 3.6 to 3.14 and nothing for macOS or Linux. The thread does not say that updating the package cures the hang; compare the version as one of the things you rule out.
pypi.orgchecked
If initialize() does return False, read last_error()
When the call comes back False rather than hanging, mt5.last_error() returns a code and a description. The negative codes on the MQL5 reference are the package talking to the terminal rather than anything a broker did: -1 generic fail, -2 invalid arguments, -3 no memory, -4 no history, -5 invalid version, -6 authorization failed, -7 unsupported method, -8 auto trading disabled, -10000 internal IPC general error, -10001 send failed, -10002 receive failed, -10003 initialization fail, and -10005 internal timeout. The -5 invalid version code is the one that names a version problem outright. Each of these codes has a page of its own in this site's MetaTrader 5 error index.
mql5.comchecked