Run Python script in Vagrant

2019-05-31 19:55发布

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?

2条回答
太酷不给撩
2楼-- · 2019-05-31 20:23

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.

查看更多
不美不萌又怎样
3楼-- · 2019-05-31 20:28

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
查看更多
登录 后发表回答