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?
Put #!/usr/bin/env python
as your shebang line to inherit the current python environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With