我继承了一些代码,这些代码是在与我不同的环境中构建的。
但是我知道我拥有正常运行所需的所有脚本。我假设我的环境设置存在问题。
这是一个非常长的,多模块的专有项目,因此我不能在此处发布该项目的任何较大部分。我的问题是,当我运行代码时出现错误:
[user@localhost mktdata.out]$ /usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
ModuleNotFoundError: No module named 'merlin.tradelogic'
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
/usr/local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
"module. Expect this to be very slow.", ImportWarning)
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
除非发现hypervolume/pyhv.py:33: ImportWarning:
是一个相关问题,否则我首先看到的错误消息部分是:
Traceback (most recent call last):
File "strats/merlin.py", line 13, in <module>
File "strats/merlin/tradeopt.py", line 11, in <module>
ModuleNotFoundError: No module named 'merlin.tradelogic'
merlin.py的开始看起来像:
#!/usr/bin/env python3
import argparse
import logging
import sys
from datetime import datetime
from merlin.cmdopt import (
add_basic_opts,add_roll_opts,add_inst_opts,add_pair_opts,
add_job_opts,add_list_of_opts
)
from merlin.mktdata import mktdataMain
from merlin.instrument import instrumentMain
from merlin.pair import pairMain
from merlin.tradeopt import tradeoptMain
from merlin.wrtconfig import wrtconfigMain
from merlin.portfolio import portfolioMain
from merlin.overview import overviewMain
from merlin.var import *
from dao.utils.functools import apply_func_seq
从merlin.py调用的tradeopt的开始看起来像:
import logging
import os.path
import lzma
import pandas as pd
import numpy as np
import array
import copy
from deap import base,creator,tools
from merlin.var import *
from merlin.stratconfig import MerlinConfig
from merlin.tradelogic import MerlinLogicPy
from merlin.utils import (
merge_paths,jobs_todo,sort_dict_by_roll,joblist_to_dict
)
from merlin.tradega import (
trade_pars,SimSettings,is_valid_pars,evaluate_c,pnl_field_num,
idx_total_pnl_pos_cost,cx_pars,mu_pars,idx_s1_trade
)
from dao.iotools.datamodel import *
from dao.fin.stats import sharpe
from dao.fin.algorithms import eaMuPlusLambda
from dao.pair.pairid import PAIR_ID,split_pair2insts
from dao.pair.spread import __pairSpread__
from dao.utils.rw import (
setup_dir,pickle_dump,pickle_load,find_folders,find_files
)
from dao.utils.roll import ROLL_ID
logger=logging.getLogger(MERLIN_MAIN_LOGGER)
def tradeoptMain(args):
我认为这表明merlin.tradelogic
丢失了。
但是,当我查看位置/home/user/merlin/bin/strats/merlin
时,我可以看到几个不同的tradelogic
模块:
它们是:
tradelogic.cpp
tradelogic.cpython-35m-darwin.so
tradelogic.pxd
tradelogic.pyx
错误中的代码引用行如下:
/home/user/merlin/bin/strats/merlin.py
中的第13行如下:
from merlin.tradeopt import tradeoptMain
/home/user/merlin/bin/strats/merlin/tradeopt.py
中的第11行如下:
from merlin.tradelogic import MerlinLogicPy
唯一带有tradelogic
的{{1}}脚本位于下面的MerlinLogicPy
中
tradelogic.pyx
我的cimport cython
from cython.view cimport array as cvarray
import numpy as np
cimport numpy as np
cdef class MerlinLogicPy:
def __cinit__(self,double entry,double exit,double stop_entry,
double stop_loss,double norm_pos,unsigned int time_loss,
bint ignore_reporting_corp)
self.thisptr=new MerlinLogic(entry,exit,stop_entry,stop_loss,
norm_pos,time_loss,ignore_reporting_corp)
如下:
$PATH
其中包含merlin([user@localhost ~]$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/user/scoleman/bin:/home/scoleman/bin:/home/user/.local/bin:/home/user/bin:/home/user/condor/bin:/home/user/scoleman/bin:/home/scoleman/bin:/home/user/condor/bin:/home/user/merlin/bin
)中的bin目录,其中包含所有代码。
我还安装了/home/user/merlin/bin
版Cython
。我需要重新编译0.29.5
吗?如果是这样,有人可以让我知道我该怎么做。
我还看到我正在运行Python3(tradelogic.pyx
在代码的顶部)。可能只有#!/usr/bin/env python3
文件似乎已使用版本3.5编译了,这可能是一个问题吗?如果可以的话,有人可以告诉我如何编译.so文件吗?
答案 0 :(得分:0)
您的项目根目录似乎是/home/user/merlin/bin/strats/
尝试将其添加到您的PYTHONPATH
中。
如果项目根目录不是PYTHONPATH
的一部分,也不是Python库的一部分,则Python将不知道从何处查找与该项目相关的模块。
这是一个很好的解释:How to use PYTHONPATH