简体   繁体   中英

Trying to Install MetaTrader5 with Python3 on a Mac

I am trying to program a Python algorithm that will work with MetaTrader5. MT5 is a trading platform used to trade forex, stocks, etc. When running

pip3 install MetaTrader5

I get a

command 'clang' failed with exit status 1

owner@Owners-MacBook-Pro ~ % pip3 install MetaTrader5
Collecting MetaTrader5
  Using cached https://files.pythonhosted.org/packages/ee/3b/4424be9ca5772ddd7f249385785d6fcacceef90fc45bf5c4946514ca245a/MetaTrader5-5.0.9.tar.gz
Building wheels for collected packages: MetaTrader5
  Building wheel for MetaTrader5 (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"'; __file__='"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-wheel-id676w5e --python-tag cp37
       cwd: /private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.7
  creating build/lib.macosx-10.15-x86_64-3.7/MetaTrader5
  copying MetaTrader5/__init__.py -> build/lib.macosx-10.15-x86_64-3.7/MetaTrader5
  running build_ext
  building 'MetaTrader5.C' extension
  creating build/temp.macosx-10.15-x86_64-3.7
  creating build/temp.macosx-10.15-x86_64-3.7/src
  creating build/temp.macosx-10.15-x86_64-3.7/src/Interprocess
  creating build/temp.macosx-10.15-x86_64-3.7/src/Connector
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DUNICODE -Isrc -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.6/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/MetaTrader.cpp -o build/temp.macosx-10.15-x86_64-3.7/src/MetaTrader.o
  In file included from src/MetaTrader.cpp:6:
  src/stdafx.h:16:10: fatal error: 'sdkddkver.h' file not found
  #include <sdkddkver.h>
           ^~~~~~~~~~~~~
  1 error generated.
  error: command 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for MetaTrader5
  Running setup.py clean for MetaTrader5
Failed to build MetaTrader5
Installing collected packages: MetaTrader5
    Running setup.py install for MetaTrader5 ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"'; __file__='"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-record-oit3fkwz/install-record.txt --single-version-externally-managed --compile
         cwd: /private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/
    Complete output (20 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.15-x86_64-3.7
    creating build/lib.macosx-10.15-x86_64-3.7/MetaTrader5
    copying MetaTrader5/__init__.py -> build/lib.macosx-10.15-x86_64-3.7/MetaTrader5
    running build_ext
    building 'MetaTrader5.C' extension
    creating build/temp.macosx-10.15-x86_64-3.7
    creating build/temp.macosx-10.15-x86_64-3.7/src
    creating build/temp.macosx-10.15-x86_64-3.7/src/Interprocess
    creating build/temp.macosx-10.15-x86_64-3.7/src/Connector
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DUNICODE -Isrc -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.6/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/MetaTrader.cpp -o build/temp.macosx-10.15-x86_64-3.7/src/MetaTrader.o
    In file included from src/MetaTrader.cpp:6:
    src/stdafx.h:16:10: fatal error: 'sdkddkver.h' file not found
    #include <sdkddkver.h>
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"'; __file__='"'"'/private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-install-5nv9pgx4/MetaTrader5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/65/d9_g2c8n6835f6nhxqqtwk900000gn/T/pip-record-oit3fkwz/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
owner@Owners-MacBook-Pro ~ % 

Could anyone explain what the error here is stating?

It looks like the package was developed only for Windows .

The relevant error is this:

In file included from src/MetaTrader.cpp:6:
src/stdafx.h:16:10: fatal error: 'sdkddkver.h' file not found
#include <sdkddkver.h>

The file sdkddkver.h is a Windows-specific file that is included with the Windows development SDK.
See:

Also, if you check the MetaTrader5 Release Files at PyPi, you'll see that there are only compiled wheels for Windows ( -cp37-cp37m-win32 , -cp37-cp37m-win_amd64 ), as opposed to other cross-platform packages like numpy (has -linux- and -macos- ) and Django (works on -any- platform).

I'm not sure about the answer of @gino-mempin but his answer logically seems correct. Here the story that leads me to have an unsuccessful attempts. I'm using Debian 10 Buster with Python3.7 . I had tried to install MetaTrader5 with pip3 in two ways as below:

python3 -m pip install MetaTrader5

or

pip3 install MetaTrader5

Unfortunately, an error raises each time:

Could not find a version that satisfies the requirement MetaTrader5 (from versions: )

I decided to manually install it, so I downloaded the package from Pypi.org and as Gino mentioned above, all the wheel packages over there, have win32 or win_amd64 prefixes which is different with my architecture. So this causes me to change the file name according to my architecture type. To do so, you should first run this code in your python to extract the proper one with your python version:

import wheel.pep425tags
print(wheel.pep425tags.get_supported())

For me the output was:

[('cp37', 'cp37m', 'linux_x86_64'), ('cp37', 'abi3', 'linux_x86_64'), ('cp37', 'none', 'linux_x86_64'), ('cp36', 'abi3', 'linux_x86_64'), ('cp35', 'abi3', 'linux_x86_64'), ('cp34', 'abi3', 'linux_x86_64'), ('cp33', 'abi3', 'linux_x86_64'),
 ('cp32', 'abi3', 'linux_x86_64'), ('cp37', 'none', 'any'), ('cp3', 'none', 'any'),
 ('cp36', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'linux_x86_64'), ('py37', 'none', 'any'), ('py3', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'),
 ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

According to my default version of python3 (cp37), the proper architecture is linux_x86_64 so I changed the filename like this:

MetaTrader5-5.0.29-cp37-cp37m-win_amd64.whl
to
MetaTrader5-5.0.29-cp37-cp37m-linux_x86_64.whl

After this change in filename, I've installed the package without any problem by this command:

python3 -m pip install MetaTrader5-5.0.29-cp37-cp37m-linux_x86_64.whl

Until here everything goes well. But in coding area, when I run the code below:

import MetaTrader5

I confront with an error that I couldn't find any solution for that yet:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-824b43c0d46a> in <module>
----> 1 import MetaTrader5

~/mt5/env/lib/python3.7/site-packages/MetaTrader5/__init__.py in <module>
    250 
    251 # import C methods to our module
--> 252 from ._core import *
    253 
    254 # internal order send

ModuleNotFoundError: No module named 'MetaTrader5._core'

I hope this problem is with my system and at least these steps works for you. If not, I would think what Gino wrote would be correct.

In Windows SO, you can put the directory site-packages inside path variable.

I hope that it is works for you ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM