Python恶意代码分析脚本报错求助:pandas模块未找到
问题:运行恶意代码分析脚本时出现ModuleNotFoundError
我运行一段基于Keras的Python恶意代码分析脚本时,出现了ModuleNotFoundError错误,提示找不到pandas模块。
运行的代码
import numpy as np import pandas as pd from copy import deepcopy import gc from col_headers import Header from experiments import Experiments, Configs from experiments.useful import timestamped_to_vector, unison_shuffled_copies, extract_neg # Load data headers = Header() c = headers.classification_col v = headers.vector_col data = pd.read_csv("data.csv") test = data[data["test_set"] == True] train = data[data["test_set"] == False] train = train.as_matrix(columns=headers.training_headers) test = test.as_matrix(columns=headers.training_headers) x_test, y_test = timestamped_to_vector(test, vector_col=v, time_start=0, classification_col=c) x_train, y_train = timestamped_to_vector(train, vector_col=v, time_start=0, classification_col=c) # Random search with thresholding rand_params = Configs.get_all() expt = Experiments.Experiment(rand_params, search_algorithm="random", data=(x_train, y_train), folds=10, folder_name="random_search_reults", thresholding=True, threshold=0.5) # parameter configurations A_B_C = Configs.get_A_B_C # Ensemble model ensemble_config = Experiments.Ensemble_configurations(list(A_B_C.values()), x_test=x_test, y_test=y_test, x_train=x_train, y_train=y_train, folder_name="test_train_results", batch_size=64) ensemble_config.run_experiments()
完整报错信息
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2022.3\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm 2022.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm 2022.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:\Users\awais ramzan\Documents\papaer\malware-prediction-rnn-master\main.py", line 2, in <module> import pandas as pd File "C:\Program Files\JetBrains\PyCharm 2022.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'pandas'
解答
错误原因
这个错误的核心是当前Python环境未安装pandas库。脚本第2行执行import pandas as pd时,系统无法在已安装的模块中找到pandas,因此抛出ModuleNotFoundError。
解决方法
1. 命令行安装
打开终端(Windows用CMD/PowerShell,Mac/Linux用终端),根据你的Python环境执行对应命令:
- 系统默认Python:
pip install pandas - 若使用Python3或虚拟环境,需先激活虚拟环境,再执行:
pip3 install pandas
2. PyCharm内直接安装
如果你用PyCharm开发,可直接在IDE内安装:
- 点击顶部菜单栏
File→Settings(Windows/Linux)或PyCharm→Settings(Mac) - 左侧导航选择
Project: [你的项目名]→Python Interpreter - 点击右侧列表上方的
+按钮,搜索框输入pandas - 选中搜索结果中的pandas,点击
Install Package完成安装
注意事项
如果项目使用了虚拟环境,务必确保是在项目对应的虚拟环境中安装pandas,否则安装到全局环境后脚本依然会找不到模块。
内容的提问来源于stack exchange,提问作者Afrasiyab Muzaffar Mian
相关产品推荐
相关产品推荐

