Run Python script in Vagrant

亡梦爱人 提交于 2019-12-23 03:47:15

问题


This is a dumb question but please help me.

Q. How do I run Python script that is saved in my local machine?

after vagrant up and vagrant ssh, I do not see any Python file in the VM. Then what if I want to run Python scripts that are saved in my Mac? I do not want to copy and paste them manually using vim.

How would you run Python script in Vagrant ssh?


回答1:


On your Guest OS there will be a folder under / called /vagrant/ this will be all the files and directories under the directory on your host machine that contains the .VagrantFile

If you put your script in that folder they will be shared with the VM.

Additionally if you are using chef as your provisioner you can use a script resource to run external scripts during the provisioning step.




回答2:


You have two options:

  1. You can go the classic route of using the shell provisioner using vagrant

    config.vm.provision "shell", inline: $script

And in your script run the python script

  1. All files are pushed in /tmp, you can possible use this to run your python script


来源:https://stackoverflow.com/questions/23232172/run-python-script-in-vagrant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!