我正在尝试编写将与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 ~ %
任何人都可以解释这里的错误是什么吗?
答案 0 :(得分:0)
该软件包似乎是仅针对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开发SDK附带的Windows特定文件。
参见:
此外,如果您在PyPi上检查MetaTrader5 Release Files,则会看到只有Windows编译过的滚轮( -cp37-cp37m-win32 , -cp37- cp37m-win_amd64 ),而不是像numpy(具有 -linux-和 -macos-)和{{ 3}}(可在 -any-平台上使用)。
答案 1 :(得分:0)
我不确定@gino-mempin的答案,但从逻辑上看他的答案是正确的。在这里,这个故事使我进行了失败的尝试。 我在 Python3.7 中使用 Debian 10 Buster 。我曾尝试通过以下两种方式通过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所述,那里的所有wheel软件包都具有 win32 或 win_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 写的是正确的。