2

When reading a Flask tutorial, the author asked me to chmod a+x run.py and then ./run.py, rather than simply python run.py as I usually do. When I ignored the author's instruction and executed python run.py, I got an ImportError.(I suspect this error has something to do with vitrualanv.)

So my question is: What's the difference between

./run.py

and

python run.py

2 Answers 2

3

I believe your suspicion is correct. Notice how he creates a virtualenv called flask:

virtualenv flask

run.py contains the following:

#!flask/bin/python
from app import app
app.run(debug=True)

The first line is called a shebang, in which the author defines that the python binary should be executed from flask/bin/python. If you instead execute python run.py, your system's default python binary is used. You could fix this by activating the virtualenv, by calling source bin/activate. Or by explicitly calling flask/bin/python run.py

Sign up to request clarification or add additional context in comments.

Comments

1

Take a look at the first line of the file:

#!flask/bin/python

It means that running:

$ ./run.py

is equivalent to:

$ flask/bin/python run.py

and since flask/bin/python is in a virtual environment, it has different modules installed.

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.