Search code examples
pythonshebang

How to go up a directory in my shebang line?


OS X using Sublime Text 2.

My app structure is this:

/project1/
+———————venv/ <— virtual enviroment
+———————app/ (has an ___init___.py file)<— Flask app
+———————alembic <— current installation of Alembic also has the env.py file
+——————— more files that refer to #!venv/bin/python

I'm using Sublime Text 2 to run my scripts, and to tell Sublime Text to use my custom Python install I've so far appended #!venv/bin/python to the beginning of my files.

The problem is, now I need to use the virtualenv for a script that resides within the alembic directory. #!venv/bin/python doesn't work, I guess because venv and alembic are sibling directories. However, I can't figure out how to go "up" one directory to invoke the correct Python interpreter.

Why doesn't #!./venv/bin/python work? doesn't the . tell Sublime to go up one directory?


Solution

  • The interpreter path in a shebang instruction must be an absolute path.

    https://en.wikipedia.org/wiki/Shebang_%28Unix%29#Syntax