0

I'm trying to run scripts for webscraping on my server (host/shared hosting) and they use something called virtualenv (I've done some research and its confusing...). However, I did install the required packages for running Selenium and some other processes. I have checked that they are installed by running the command:

$ pip show selenium

Which returns Location: /home/s49674/virtualenv/python/3.9/lib/python3.9/site-packages

However, when I run my python code, it gives me the error that the module is not installed.

What I have to do is to activate the virtualenv through ssh, and call the python script through the ssh. But this doesn't allow me to automate script execution through cronjob. Do you know a solution to this? So far I haven't found anything that works. It doesnt matter where I store the python script, it cant find the modules.

  • assuming it's linux OS, the command is `source /bin/activate`. Once activated, install selenium here – neilharia7 Apr 05 '22 at 09:15
  • @neilharia7 you cannot activate venv in cron, that's the problem – h4z3 Apr 05 '22 at 09:15
  • 1
    To use venv in cron, you gotta use full path to the executable from the venv. `cd /full/path/to/project/ && /location/to/venv/bin/python my_file.py`. Remember driver needs to be in PATH and cron uses different PATH (of course project's location will be added to PATH - because of our cd :) ) – h4z3 Apr 05 '22 at 09:15
  • Agreed @h4z3, I just answered his first question, `how to activate the virtualenv through ssh`. – neilharia7 Apr 05 '22 at 09:22

0 Answers0