为什么python在windows和linux中不同地向pythonpath追加script dir?

2024-10-02 12:23:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样的结构:

测试目录:

.
├── __init__.py
└── nested
    ├── __init__.py
    └── test.py

然后我运行脚本(python2.7)如下:

~/tmp/test$./nested/test.py

你知道吗测试.py地址:

import sys
print sys.path

在linux上得到了这个:

['/home/xliivdeb/tmp/test/nested', '/home/xliivdeb/tmp/test', ..]

在windows xp上:

['E:\\tmp\\test\\nested', 'c:\\Python27\\lib\\site-packages\\distribute-0.6.28-py2.7.egg', ..]

区别在于:

在linux上:

  • 脚本目录('/home/xliivdeb/tmp/test/nested')和
  • 当前目录('/home/xliivdeb/tmp/test')

在windows上,仅附加了:

  • 脚本目录('E:\tmp\test\nested')

为什么?怎么处理?如果是windows,是否必须手动附加它?你知道吗


Tags: pytestimport目录脚本homeinitlinux

热门问题