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.

2

2 Answers 2

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).

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

Comments

-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.

3 Comments

It's not a file permission issue. The utils file have all the necessary permission.
Juts found this- sudo chown -R your_username:your_username path/to/virtuaelenv/ stackoverflow.com/questions/19471972/…
I haven't created venv as a root user. Anyway I have tried this. It didn't work :(

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.