尝试在 Mac 上使用 Python3 安装 MetaTrader5

Posted

技术标签:

【中文标题】尝试在 Mac 上使用 Python3 安装 MetaTrader5【英文标题】:Trying to Install MetaTrader5 with Python3 on a Mac 【发布时间】:2019-12-28 03:01:57 【问题描述】:

我正在尝试编写一个适用于 MetaTrader5 的 Python 算法。 MT5是一个用于交易外汇、股票等的交易平台。运行时

pip3 install MetaTrader5

我得到一个

命令“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 ~ % 

谁能解释这里的错误是什么?

【问题讨论】:

【参考方案1】:

看起来这个包是只为 Windows 开发的

相关错误是这样的:

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

文件 sdkddkver.h 是 Windows 特定文件,包含在 Windows 开发 SDK 中。 见:

What is sdkddkver.h? what is SDKDDKVer.h for?

另外,如果你在 PyPi 上查看MetaTrader5 Release Files,你会发现只有 Windows 编译的***(-cp37-cp37m-win32-cp37-cp37m- win_amd64),而不是像numpy(具有-linux--macos-)和Django(适用于-any- 平台)。

【讨论】:

您对此问题的解决方案是什么? Vmware、docker 还是其他? @BrenoPerucchi 我没有办法在非 Windows 机器上安装它。我的回答只是为了解决 OP 的问题,为什么它会在 Mac 上出错(以及如何检查它)。如果您的问题是如何在特定的非 Windows 机器上安装它,我建议您提出一个新问题。【参考方案2】:

我不确定@gino-mempin 的答案,但他的答案在逻辑上似乎是正确的。这是导致我尝试失败的故事。 我将 Debian 10 BusterPython3.7 一起使用。我曾尝试通过以下两种方式使用 pip3 安装 MetaTrader5:

python3 -m pip install MetaTrader5

pip3 install MetaTrader5

不幸的是,每次都会引发错误:

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

我决定手动安装它,所以我从Pypi.org下载了包,正如上面提到的Gino,那里所有的***包,都有win32win_amd64 前缀,这与我的架构不同。 所以这导致我根据我的架构类型更改文件名。为此,您应该首先在您的 python 中运行此代码,以使用您的 python 版本提取正确的代码:

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

对我来说,输出是:

[('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')]

根据我默认的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

在更改文件名后,我通过以下命令安装了软件包,没有任何问题:

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

直到这里一切顺利。但是在编码区,当我运行下面的代码时:

import MetaTrader5

我遇到了一个我还没有找到任何解决方案的错误:

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'

我希望这个问题出在我的系统上,至少这些步骤对你有用。如果不是,我认为 Gino 写的是正确的。

【讨论】:

【参考方案3】:

在 Windows SO 中,您可以将目录 site-packages 放在 path 变量中。

我希望它对你有用;)

【讨论】:

以上是关于尝试在 Mac 上使用 Python3 安装 MetaTrader5的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Mac OS Sierra 上使用 Python3.5 绝对安装 virtualenvwrapper?

我无法在 Mac 上使用 Python3 安装 Psycopg2。我已经安装了 Python3 和 pip3

在 Mac OS X Yosemite 上安装 Python3

如何在 mac os x 上使用 gunicorn 和 python3.8 而不是 python3.9?

python安装教程(mac版)-python安装步骤

如何使用 Python 3 在 Mac 上安装 pyaudio?