0

I have a python script named utils (note without any .py extension). Where I have some utility functions. The path is also added in PATH variable.

#!/usr/bin/env python3

import click, sys

@main.command('echo', context_settings=dict(help_option_names=['-h', '--help']))
def echo_test():
    click.echo("Hello World")
    sys.exit(0)

It works fine. Now I can run from anywhere utils echo.

I am trying to make the script to use virtualenv instead of the global python. I have tried

#!/path/to/venv/bin python3

import click, sys

Then it throws me error permission denied

Permissions for utils file are -rwxr-xr-x

Any idea how could I use venv with script.

Swati
  • 3
  • 3
  • Does this answer your question? [Permission denied when launch python script via bash](https://stackoverflow.com/questions/5807663/permission-denied-when-launch-python-script-via-bash) - maybe via this answer: https://stackoverflow.com/a/5822293/573034 – Paolo Apr 21 '21 at 10:31
  • Unfortunately not. This file has all the permissions – Swati Apr 21 '21 at 10:51

2 Answers2

0

If your code is pasted correctly, your problem is that you are trying to execute a directory with your she-bang, not Python, because you have a space rather than a slash as a separator:

#!/path/to/venv/bin python3

rather than:

#!/path/to/venv/bin/python3

EDIT: By the way, is there a reason you want to change the code and not just activate the virtual environment, like it's supposed to be used?

If you want to do it, you can just:

$ source path/to/venv/bin/activate<.optional_extension>

You need the optional extension if you use a shell other than Bash (probably other Bourne-like shells too).

Larry
  • 427
  • 2
  • 10
-1

Try changing the file permissions via this command:

chmod 755

chmod -R 755 on the /usr/lib/python/site-packages/virtualenv

or even

chmod +x

Suggest you read the man page for chmod by using this command

man chmod 

if you are not sure.

  • It's not a file permission issue. The utils file have all the necessary permission. – Swati Apr 21 '21 at 10:48
  • Juts found this- `sudo chown -R your_username:your_username path/to/virtuaelenv/` https://stackoverflow.com/questions/19471972/how-to-avoid-permission-denied-when-using-pip-with-virtualenv – x0xRumbleLorex0x Apr 21 '21 at 10:52
  • I haven't created venv as a root user. Anyway I have tried this. It didn't work :( – Swati Apr 21 '21 at 11:00