-
Notifications
You must be signed in to change notification settings - Fork 259
Vagrant Environments
This wiki information is valid only for Anaconda 1.x and is currently DEPRECATED, please, refer to the wiki page about how to setup Vagrant environments for Anaconda v2
Anaconda can use vagrant boxes environments to lint and complete your code. Some IDE utilities will not work when vagrant environments are in use, for example the Goto IDE command will not work if you try to go to a file that is stored in the vagrant box.
In order to use remote python interpreters living on guest vagrant machines with anaconda the user has to prepare the guest environment first following the next steps.
Your guest machine is going to use a modified version of anaconda_lib
and anaconda's jsonserver
which you can just checkout from the anaconda git repository:
(vagrant guest machine) $ git clone https://github.com/DamnWidget/anaconda
(vagrant guest machine) $ cd anaconda
(vagrant guest machine) $ git checkout vagrant_server
Now that you have a fresh copy of the vagrant server you can edit the configuration file to adapt it to your needs (you can configure vagrant support in three different ways, take a look at the next sections to know how to configure network properly).
The vagrant_server configuration file is just a python script that defines the value of four variables:
python_interpreter = "python3" # the python interpreter to use
project = "MyAmazingProject" # the name of the project (mainly for logging purposes)
extra_paths = None # homologous to regular anaconda extra_paths (they must live in the guest machine)
port = '19360' # the port to listen on (must be a string)
Now we can just start the server executing with any python interpreter the server.py
file in the root of the vagrant_server
branch:
(vagrant guest machine) $ python server.py
Vagrant environments work only per-project, that means there is no a global anaconda vagrant configuration. Anaconda will try to use always the local python interpreter if not specific project configuration is provided so the user will always provide a valid project configuration file in order to use vagrant support with anaconda.
A vagrant configured anaconda project looks like this
{
...
"settings": {
"vagrant_environment": {
"directory": "~/vagrant", // Directory where the Vagranfile is located in your local machine
"machine": "Ubuntu-12.0", // if no machine is provided default is used
"network": {
"mode": "private", // configured vagrant network mode
"address": "192.168.5.10", // guest machine IP address
"port": 19360 // guest machine port
}
}
}
}
Anaconda can't switch from regular to vagrant so you will need to restart your Sublime Text 3
Vagrant support works only when vagrant network is properly configured, the possible valid configurations are shown below
Forwarded ports allow you to access a port on your host machine and have all data forwarded to a port on the guest machine, over either TCP or UDP. Configure one is as easy as set the right configuration in your Vagranfile
:
config.vm.network :forwarded_port, guest: 19360, host: 1936
Then you can configure your anaconda to use this port in your local host to connect to the guest machine jsonserver:
...
"network": {
"mode": "forwarded",
"port": 1936
},
Private networks allow you to access your guest machine by some address that is not publicly accessible from the global internet. You can configure a private network for your guest machine using setting up the vm.network
option in your Vagrantfile
, for example:
config.vm.network "private_network", ip: "192.168.5.10"
You have to specify a vagrant netowork configuration in your anaconda configuration, for private networks it should be:
...
"network": {
"mode": "private",
"address": "192.168.5.10",
"port": 19360
},
Public networks allow your guest machines to be allocated from others hosts in your local network (or event from the internet). To configure a public network just set the vm.network
config option in your Vagrantfile
like:
config.vm.network :public_network
In this case we don't have to specify the address of our guest machine in the anaconda configuration (mainly because we don't know it):
...
"network": {
"mode": "public",
"port": 19360,
"interface": "eth1" // this optional parameter is used to discover the right IP where to connect with
},
When the vagrant network mode is set as public, anaconda will discover the guest IP address through the vagrant ssh
command in the local machine.