Numpy已安装并正在运行,但是尽管重新安装了anaconda并在重新安装之前清除了numpy,但突然我仍然丢失了模块错误

时间:2020-10-05 10:08:38

标签: python numpy ubuntu-18.04

我在一个简单的python脚本中使用numpy,该脚本在循环中调用并运行另一个程序。它运行了好几天,然后我需要去某个地方,所以我试图取消该过程,我很懒,最后只是关闭了终端。下次尝试运行它时,我开始出现以下错误:

(基本)cb27g11 @ cb27g11-Precision-7510:〜/ Development / Ciara $ sudo ipython3 Test_script.py

ModuleNotFoundError Traceback(最近一次通话) ()中的/home/cb27g11/Development/Ciara/Test_script.py 1个导入子流程 2导入文件输入 ----> 3将numpy导入为np 4 5 tan_beta = [20,25,30,35,40] #tantan值数组

ModuleNotFoundError:没有名为“ numpy”的模块

但是numpy肯定仍然安装。我使用anaconda,文件中有numpy。如果我在终端中启动shell并导入numpy,就没有问题,并且“哪个python”返回:

/home/cb27g11/anaconda3/bin/python

所以路径似乎是完整的。

我尝试完全卸载numpy和anaconda,清除计算机中与numpy相关的所有文件,然后重新安装都没有成功。

然后我通过pip3安装了numpy,我一直在浏览环境和蟒蛇文件以查看路径是否损坏,但是我正在努力寻找解决方法。

以防万一我的小脚本有问题,请在下面添加它:

import fileinput
import numpy as np

tan_beta = [20, 25, 30, 35, 40] #Array of tan(beta) values
sin_bma = np.linspace(0.9, 1.1, 22)#Array of sin(beta-alpha) values
hcm =  250 # Mass of charged Higgses in GeV
textfilepath = '/home/cb27g11/models/mg_run.txt' #path to txt file madgraph will use
Process = 'AD_noCharge'

def the_main_event():
    with open('/home/cb27g11/Development/Ciara/mg_run_basic.txt','r') as old_card:
        text =old_card.read() #stores string of old_card ready for editing
    for i in range(0, len(tan_beta)):
        tb = tan_beta[i] # loops over tan(beta) values
        for j in range(0, len(sin_bma)):
            sbma = sin_bma[j] # loops over sin(beta-alpha) values
            make_input(tb, sbma, hcm, text)
            run_madgraph()

def make_input(Tb, Sbma, Hcm, Text):
# inputs are the value of tan_beta, the value of sin(beta-alpha) values, the desired mass for the charged higgses and a string of text

    with open(textfilepath, 'w') as new_card:
    #simulation card, the .txt file that gets fed to madgraph
        sim_card = Text.replace('TBV', str(Tb))
        sim_card = sim_card.replace('SBMAV', str(Sbma))
        sim_card = sim_card.replace('HCMV', str(Hcm))
        sim_card = sim_card.replace('NAME', str(Process)+'_' + str(Tb) +'_' + str(Sbma))
        new_card.write(sim_card) # saves new txt file for madgraph in ~/models (as this is linked to docker as an input)
    

def run_madgraph():
# starts madgraph in docker with a volume type output linked to $HOME/output on laptop and mount type input linked to $HOME/models, then tells it to run mg5_aMC using mg_run.txt as a file for it. 
    subprocess.run('sudo docker run -t -i -v $HOME/outputs:/var/MG_outputs --mount type=bind,source=$HOME/models,target=/app hfukuda/madgraph /home/hep/MG5_aMC_v2_6_3_2/bin/mg5_aMC /app/mg_run.txt', shell=True)

the_main_event()```

0 个答案:

没有答案