---
title: "命令行运行python时找不到模块的问题“ImportError: No module named”"
author: "eric_wyf"
date: "2011-09-21T16:09:55Z"
tags: []
categories: ["编程语言"]
slug: "python-importerror-no-module-named"
draft: false
lastmod: "2011-09-21T16:09:55Z"
id: 1177164
url: "https://eric-wyf.iteye.com/blog/1177164"
---

自己写了一个python脚本，使用的是eclipse + pydev插件的IDE

在IDE中执行没问题，在命令行中，就出现“ImportError: No module named” 错误

项目的目录结构

 

执行python LogAnalysis.py报错 ImportError: No module named com.util

在LogAnalysis.py中加入sys.path.append(os.path.abspath('%s/../..' % sys.path\[0]))。ok了

sys.path在IDE中和在命令行中是不同的