Reputation: 3676
So what I'm trying to do is have an executable python script so that I can link to it on my path and run it from anywhere, but I need to run it within a virtual environment locally.
Currently I have a symbolic link in /usr/local/bin -> ~/dev/project/tools/rest_client.py
Inside the project directory the permissions are:
-rwxr-xr-x 1 luke staff 3229 Dec 3 10:21 rest_client.py
The rest-client file
#!/Users/luke/Envs/py2.7/bin/python
def main():
#do stuff
I can run it from any directory like this when I run rest-client
I would like to be able to check this file into a git repo and share it with others, without hardcoding the virtualenv into the file, but to still be able to execute it from anywhere on my machine.
If I change the first line to
#!/usr/bin/python
Then it wont run in the virtual environment unless I execute it via
workon py2.7
python ~/dev/project/tools/rest_client.py
Is there a proper way to do this is UNIX without using something like an alias?
Upvotes: 8
Views: 7147
Reputation: 32532
Put #!/usr/bin/env python
as your shebang line to inherit the current python environment.
Upvotes: 14