简体   繁体   English

尝试在 Mac 上使用 Python3 安装 MetaTrader5

[英]Trying to Install MetaTrader5 with Python3 on a Mac

I am trying to program a Python algorithm that will work with MetaTrader5.我正在尝试编写一个适用于 MetaTrader5 的 Python 算法。 MT5 is a trading platform used to trade forex, stocks, etc. When running MT5是用于交易外汇、股票等的交易平台。运行时

pip3 install MetaTrader5

I get a我得到一个

command 'clang' failed with exit status 1命令“clang”失败,退出状态为 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 .看起来这个包是只为 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.文件sdkddkver.h是 Windows 特定的文件,包含在 Windows 开发 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).此外,如果您检查 PyPi 上的MetaTrader5 发布文件,您会发现只有 Windows 编译轮子( -cp37-cp37m-win32-cp37-cp37m-win_amd64 ),而不是其他跨平台软件包,如numpy (有-linux--macos- )和Django (适用于-any-平台)。

I'm not sure about the answer of @gino-mempin but his answer logically seems correct.我不确定@gino-mempin的答案,但他的答案在逻辑上似乎是正确的。 Here the story that leads me to have an unsuccessful attempts.这里的故事导致我有一次不成功的尝试。 I'm using Debian 10 Buster with Python3.7 .我正在使用Debian 10 BusterPython3.7 I had tried to install MetaTrader5 with pip3 in two ways as below:我曾尝试通过以下两种方式使用 pip3 安装 MetaTrader5:

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.我决定手动安装它,所以我从Pypi.org下载了这个包,正如上面 Gino 提到的,那里所有的轮子包都有win32win_amd64前缀,这与我的架构不同。 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:为此,您应该首先在您的 python 中运行此代码以使用您的 python 版本提取正确的代码:

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:根据我默认的 python3 (cp37) 版本,正确的架构是linux_x86_64,所以我像这样更改了文件名:

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.在 Windows SO 中,您可以将目录site-packages放在路径变量中。

I hope that it is works for you ;)我希望它对你有用;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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