python 导入在服务器环境中中断但在我的计算机上运行正常

python import breaks in server environment but works fine on my computer

我有一个研究服务器,我正在使用它来 运行 一些 python 脚本。服务器只有python 2.4。我的问题是,当我尝试 运行 服务器上的测试时,它会中断导入语句。我的文件结构是这样的:

|-- README.md
|-- poly.py
`-- tests
    |-- __init__.py
    |-- test_foil.py

tests/__init__.py 长得像

from test_foil import *
unittest.main()

test_foil.py最初看起来像

import unittest
from poly import Poly

在我的电脑上,当我 运行 python tests/__init__.py 测试执行时。但是当我 运行 它在服务器上时,我得到错误

from test_foil import *
Traceback (most recent call last):
  File "tests/__init__.py", line 1, in ?
    from test_foil import *
  File "/home/simon_team/partition_poly/tests/test_foil.py", line 2, in ?
    from poly import Poly
ImportError: No module named poly

它对 运行 服务器上的测试不是 100% 重要,但在 运行 实际代码之前确保代码与 2.4 兼容是一种非常方便的方法。我终其一生都无法弄清楚为什么它在两台机器上的行为不同,因为文档没有表明 import 的行为从 2.4 更改为 2.7

import sys

sys.path.append("path_to_directory")

from poly import Poly