简体   繁体   English

通过SSH进入我的Vagrant虚拟机以运行python脚本…但是除非我在VM本身中,否则python脚本不起作用

[英]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. 我有一个Vagrant虚拟机,用于运行自动化测试。 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. 在通过SSH连接到该虚拟机并从相同的确切目录运行相同的确切脚本之后,关于不存在的模块和某些不存在的文件,我遇到了错误。 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. 我用nano制作了一个随机的txt文件,当我查看放置txt的目录时,确实可以看到该txt文件出现在SSH终端中。 What could be different about the environment from SSH's perspective? 从SSH的角度来看,环境有什么不同? Why would executing the same python script from the VM's terminal and from the SSH terminal have drastically different results? 为什么从VM终端和SSH终端执行相同的python脚本会产生截然不同的结果?

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. 我从命令行执行的python脚本启动了这些测试。

You aren't using the same Python executable in the two environments. 您在两种环境中没有使用相同的Python可执行文件。 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: SSH进入虚拟机时,请在执行测试脚本之前运行以下命令:

source /home/vagrant/regression_venv/bin/activate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Vagrant中运行Python脚本 - Run Python script in Vagrant 在Vagrant中运行Python脚本 - Run a Python script in Vagrant 为什么我的Python脚本不起作用? - Why doesn't my Python script work? 如果我用“ python -m”运行它,如何重新启动我的Python脚本? - How to restart my Python script if I run it with “python -m”? 没有完整路径,为什么我安装的(在虚拟环境中的Windows上)python脚本无法运行? - Why doesn't my installed (on Windows in a virtual environment) python script work without a full path? Python脚本无法正常自行重启 - Python script doesn't restart itself properly 我正在学习如何使用Vagrant,我正在尝试运行python脚本 - I'm learning how to use Vagrant and I was trying to run a python script 在流浪汉上运行python脚本 - run python script on vagrant up 如何在其他Windows机器上的虚拟环境中本地运行python脚本并使其始终运行? - How to run a python script locally in a virtual environment on someone elses windows machine and have it consistently work? 当我使用“python3 绝对路径”运行 Python 脚本时,它不起作用,但是当我浏览文件夹然后运行时它起作用 - Python script doesn't work when i run it with “python3 absolute path” but work when i navigate on the folder then run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM