0

我在main.py目录下的shell中运行带有“python main.py”的python脚本,它报告错误并停止。但是当我使用完整路径运行相同的脚本时,如“python /home/work/main.py " 在同样的情况下,它被阻塞,直到我用“Ctrl+C”中断它,它被中断时报告错误。但是如果没有错误,它似乎是一样的,正常的。

不知道为什么,谁能告诉我?

错误:

^CTraceback (most recent call last):
  File "/home/work/video/fe/tvservice/main.py", line 17, in <module>
    from conf.settings import DATABASE_TV, WEB_SERVER_CONFIG, DATABASE_TV_MASTER,DATABASE_TV_LOG_MASTER, ZOOKEEPER_CONFIG
  File "/home/work/video/fe/tvservice/conf/settings.py", line 1
    hello world
              ^

settings.py 你好世界

4

1 回答 1

1

如果您从完全相同的目录执行它,并且您正在执行完全相同的文件,那么大多数应该是相同的。您可能会想到的区别是:

sys.argv[0]  # will be either '/home/work/main.py' or 'main.py'

只要确保:

  • 您正在执行相同的文件,
  • 您正在使用相同的虚拟环境(或在两种情况下都不使用它),
  • 您正在从同一目录执行命令,

以下结果应该完全相同:

# Imports, so the commands will not fail
import os
import sys

# These should be the same in both cases - print them/log/whatever and compare
os.getcwd()
sys.path
于 2013-09-10T02:57:17.203 回答