0

I have a following problem. I have installed packages into my venv. Now I would like run my python script from terminal in Ubuntu. But I got an error

from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

I have found that I shoud use shebag. So I put the path to my venv on the first line in my script.py like this: #!/home/vojta/Desktop/my_file/venv/bin python. But I still got the same error. How can I fix it please?

vojtam
  • 1,157
  • 9
  • 34
  • How are you running the file and are you sure that this is the right location to python that you want to access? Also see this: https://stackoverflow.com/questions/6908143/should-i-put-shebang-in-python-scripts-and-what-form-should-it-take – Andrew Wei Dec 05 '21 at 11:25
  • @AndrewWei I open terminal in the location of the script `/home/vojta/Desktop/my_file` and try `python3 file.py`. I read your link, but it did not help me – vojtam Dec 05 '21 at 11:27
  • If you use a shebang, you should be able to `chmod` to make the file executable and then execute it with something like `./file.py`. It could also be that selenium is not installed in the virtual environment/with the python you're using. – Andrew Wei Dec 05 '21 at 11:30
  • Selenium is definitely installed in venv, because when I try to run it from my IDE its fine. – vojtam Dec 05 '21 at 11:39
  • @AndrewWei btw, should I use `#!/usr/bin/venv python3` or the full path as I descriped in my question? I am little bit confused – vojtam Dec 05 '21 at 11:54
  • You might want to read up on how to run scripts that use shebangs: https://superuser.com/questions/828737/run-python-scripts-without-explicitly-invoking-python I'm not sure if you have the right path to the python you want to target/if you're invoking it correctly. – Andrew Wei Dec 05 '21 at 11:57

0 Answers0