HandleThatError HandleThatError - 10 months ago 36
Python Question

SSHed into my Vagrant virtual machine to run a python script...but the python script doesn't work unless I'm in the VM itself

I have a Vagrant virtual machine that I use for running automated tests. When I vagrant up and open up the console in my virtual machine, I'm able to start my tests with a simple command on the command line. After SSHing into that virtual machine and running the same exact script from the same exact directory, I'm getting errors with regards to modules not existing and certain files not existing. What might be the case?

I used nano to make a random txt file and surely enough I saw that the txt file appeared in my SSH terminal when I looked in the directory where I placed the txt. What could be different about the environment from SSH's perspective? Why would executing the same python script from the VM's terminal and from the SSH terminal have drastically different results?

I'm using the robots framework and selenium for my testing. The python script I'm executing from the command line kicks off those tests.

Answer Source

You aren't using the same Python executable in the two environments. For some reason, your vagrant console is using a virtual environment.

When you SSH into your VM, run this command before executing your test script:

source /home/vagrant/regression_venv/bin/activate