|
a |
|
b/guide/using_vagrant.md |
|
|
1 |
# Using Vagrant |
|
|
2 |
|
|
|
3 |
[Vagrant](https://www.vagrantup.com/) is a command line utility for creating project-specific virtual machines (VMs). |
|
|
4 |
MedaCy uses Vagrant to enable development on different platforms, including Windows. |
|
|
5 |
This guide will instruct you on how to use Vagrant within PyCharm or from the command line. |
|
|
6 |
|
|
|
7 |
## Installations |
|
|
8 |
|
|
|
9 |
The only additional software you need to use Vagrant is VirtualBox and Vagrant itself. |
|
|
10 |
This guide assumes that if you plan to use PyCharm, you have the professional edition |
|
|
11 |
and are already familiar with how to use its base features. |
|
|
12 |
The full user guide for PyCharm can be found [here](https://www.jetbrains.com/help/pycharm/meet-pycharm.html). |
|
|
13 |
|
|
|
14 |
### Installing VirtualBox |
|
|
15 |
|
|
|
16 |
[VirtualBox](https://www.virtualbox.org/) is an open-source program for creating virtual machines. |
|
|
17 |
Vagrant will utilize it to create your medaCy virtual machine. |
|
|
18 |
You can download the version appropriate for your machine [here](https://www.virtualbox.org/wiki/Downloads) |
|
|
19 |
and follow the installation instructions that they provide. |
|
|
20 |
|
|
|
21 |
### Installing Vagrant |
|
|
22 |
|
|
|
23 |
Go to the [installation page](https://www.vagrantup.com/downloads.html) for Vagrant and select the version |
|
|
24 |
appropriate for your machine. You will likely need to restart your machine after this step. |
|
|
25 |
|
|
|
26 |
Please also run this command to allow for the customization of the Vagrant box's disk size: |
|
|
27 |
```bash |
|
|
28 |
$ vagrant plugin install vagrant-disksize |
|
|
29 |
``` |
|
|
30 |
|
|
|
31 |
## Vagrant for medaCy |
|
|
32 |
|
|
|
33 |
Each project that uses Vagrant requires there to be a file in the root directory of the project named |
|
|
34 |
Vagrantfile. MedaCy distributes with this file already configured. |
|
|
35 |
|
|
|
36 |
### At the command line |
|
|
37 |
|
|
|
38 |
### Vagrant up |
|
|
39 |
|
|
|
40 |
This step includes downloading an Ubuntu operating system and should be performed with a strong internet |
|
|
41 |
connection for fastest results. |
|
|
42 |
|
|
|
43 |
From the command line, navigate to the directory containing your clone of medaCy, and run this command: |
|
|
44 |
|
|
|
45 |
```bash |
|
|
46 |
$ vagrant up |
|
|
47 |
``` |
|
|
48 |
|
|
|
49 |
This command will create your new medaCy VM using the specifications in the Vagrantfile. |
|
|
50 |
You will be using this command every time you want to start up your VM, |
|
|
51 |
but since this is its first activation, it will take a while. |
|
|
52 |
While you wait, the operating system for the medaCy VM (Ubuntu), Python 3, and medaCy and all its dependencies |
|
|
53 |
are being downloaded and installed. Once these downloads complete, |
|
|
54 |
you won't have to wait for them every time you run `vagrant up`. |
|
|
55 |
|
|
|
56 |
### Let's take a look |
|
|
57 |
|
|
|
58 |
Now run: |
|
|
59 |
|
|
|
60 |
```bash |
|
|
61 |
$ vagrant ssh |
|
|
62 |
``` |
|
|
63 |
|
|
|
64 |
When this command finishes, you'll be inside your new VM. Specifically, you'll be in the home folder. |
|
|
65 |
You don't particularly need to be here, so run these commands: |
|
|
66 |
|
|
|
67 |
```bash |
|
|
68 |
vagrant@ubuntu-bionic:~$ cd ../.. |
|
|
69 |
vagrant@ubuntu-bionic:/$ cd vagrant |
|
|
70 |
vagrant@ubuntu-bionic:/vagrant$ ls |
|
|
71 |
``` |
|
|
72 |
|
|
|
73 |
After running the first command, you could run `ls` to see the root directory of your |
|
|
74 |
VM, if you feel so inclined. We're interested in what's in the `/vagrant` subdirectory. |
|
|
75 |
The `/vagrant` directory of the VM contains your copy of the medaCy repository, and is shared between the |
|
|
76 |
VM and the directory on the host machine containing the Vagrantfile. |
|
|
77 |
|
|
|
78 |
### So should I continue by setting up a virtual environment for medaCy? |
|
|
79 |
|
|
|
80 |
No. Think of your VM as an enhanced virtual environment. When the VM was created, medaCy |
|
|
81 |
and all of its dependencies were installed on the base installation of Python 3. |
|
|
82 |
In theory, you'll only be using this VM for medaCy, so there's no need to |
|
|
83 |
create a separate environment for it. |
|
|
84 |
|
|
|
85 |
Because of how Python 3 was installed on the VM, you will need to use the command `Python3` rather than `Python`, |
|
|
86 |
and `pip3` instead of `pip`; `pip3` may require using `sudo`. |
|
|
87 |
|
|
|
88 |
### What now? |
|
|
89 |
|
|
|
90 |
Now that you have a medaCy-specific Ubuntu VM with a shared folder between the VM and your machine, |
|
|
91 |
you can edit any file you'd like in whatever text editor you choose, then run it within the VM from |
|
|
92 |
the command line. You won't need to worry about whether or not medaCy is compatible with your host machine. |
|
|
93 |
|
|
|
94 |
Keep in mind that the VM has limited resources and should only be used for developing |
|
|
95 |
medaCy itself and generating predictions. Model training requires significantly more resources and |
|
|
96 |
should be done on a machine with a significant amount of memory. |
|
|
97 |
|
|
|
98 |
### Exiting and turning off the VM |
|
|
99 |
|
|
|
100 |
Having a VM running requires a lot of resources from your host machine. When you're |
|
|
101 |
done using the VM, run these commands. |
|
|
102 |
|
|
|
103 |
```bash |
|
|
104 |
vagrant@ubuntu-bionic:~$ exit |
|
|
105 |
$ vagrant halt |
|
|
106 |
``` |
|
|
107 |
|
|
|
108 |
`$ exit` will leave the VM from the command line but leave it running in the background; |
|
|
109 |
`$ vagrant halt` will turn it off. |
|
|
110 |
|
|
|
111 |
## In PyCharm |
|
|
112 |
|
|
|
113 |
### Tools > Vagrant > Up |
|
|
114 |
|
|
|
115 |
PyCharm Professional Edition provides features for interacting with Vagrant VMs. |
|
|
116 |
This guide will cover the basics, but the developers of PyCharm provide a guide [here](https://www.jetbrains.com/help/pycharm/vagrant-support.html). |
|
|
117 |
|
|
|
118 |
Open your medaCy project in PyCharm and select Tools > Vagrant > Up. This is the same |
|
|
119 |
as running `vagrant up` from the terminal. |
|
|
120 |
|
|
|
121 |
### Tools > Start SSH session... |
|
|
122 |
|
|
|
123 |
Likewise, Tools > Start SSH session... is the same as `$ vagrant ssh`. PyCharm will list |
|
|
124 |
your Vagrant VM as an option to SSH into. You will then be able to interact with the VM at |
|
|
125 |
its own terminal. |
|
|
126 |
|
|
|
127 |
From Tools > Vagrant, you also have the option to select Halt. |
|
|
128 |
|
|
|
129 |
### Configuring the interpreter |
|
|
130 |
|
|
|
131 |
While you're developing medaCy in PyCharm, you probably don't want to run each script from the command line. |
|
|
132 |
This section details how to set the project interpreter to be the installation of Python 3 on the VM. |
|
|
133 |
|
|
|
134 |
Select File > Settings, and then on the settings menu, select Plugins. Enable the |
|
|
135 |
Remote Interpreter plugin. |
|
|
136 |
|
|
|
137 |
Once remote interpreters are enabled for PyCharm, you will need to configure the remote interpreter |
|
|
138 |
for this project. The plugin is already designed to work with Vagrant, so this will be easy. |
|
|
139 |
|
|
|
140 |
Again, go to File > Settings, and select Project: medacy > Project Interpreter. Select the gear |
|
|
141 |
icon on the right side of the dialogue box and select "add". Another dialogue box will appear. |
|
|
142 |
Select "Vagrant" on the left side of the new box. Set the Python interpreter path to |
|
|
143 |
`usr/bin/python3`. |
|
|
144 |
|
|
|
145 |
## Finishing up |
|
|
146 |
|
|
|
147 |
We hope that this guide was able to clarify how to configure Vagrant for medaCy. |
|
|
148 |
Should you encounter any issues, please follow the links throughout the guide |
|
|
149 |
to read the documentation for Vagrant and PyCharm. If you believe the problem is |
|
|
150 |
specific to Vagrant is configured for this project, please [open a new issue](https://github.com/NLPatVCU/medaCy/issues). |