0

I run a python script with "python main.py" in the shell under the main.py directory, it reports an errors and stops.But when I run the same script with full path like "python /home/work/main.py" under the same circumstance, It is blocked until I interrupt it with "Ctrl+C", a error is reported when it is interrupted.But it seems go the same and normally if no errors exist.

I don't know why, can somebody tell me ?

the errors:

^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 hello world

4
  • It's better to paste the error informations here. Commented Sep 10, 2013 at 2:50
  • 1
    Your question is somewhat confusing. Could you tell us what errors you were getting when you ran each piece of code? Also, when you execute the first one: python main.py, make sure you are in the correct directory by using cd /home/work before you execute the main.py file. Commented Sep 10, 2013 at 2:53
  • @venus.w: It looks like a SyntaxError, but the traceback should include information about type of the error. Commented Sep 10, 2013 at 2:58
  • 1
    In short, Tadeck's answer is correct. There should be no difference if they are in fact the same file aside from sys.argv[0] being different. Executing it through a different path has no effect on how the script runs. Commented Sep 10, 2013 at 3:18

1 Answer 1

1

If you are executing it from exactly the same directory, and you are executing exactly the same file, most should be the same. The difference that you could possibly think about is value of:

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

Just make sure that:

  • you are executing the same file,
  • you are using the same virtual environment (or not using it in both cases),
  • you are executing the command from the same directory,

Results for the following should be exactly the same:

# 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.