This article has been included in the latest edition of PyCharm Chinese Guide. For more tips on how to use PyCharm, please visit PyCharm 2.0 online

In the development process, it is hard to avoid the embarrassment of half an hour of development and half a day of environment.

Sometimes the environment built by myself on my computer can only be used by myself and cannot be reused to my colleagues, which leads to the extreme waste of team labor.

Here, Mingo shows you a way to package the Python environment you’ve worked so hard to build on your computer for your colleagues to enjoy.

Download and install Vagrant

The vagrant download address: www.vagrantup.com/downloads

Once installed, execute the Vagrant Box add Hashicorp/Precise64 command to download an image on your computer. This image is only for demonstration purposes, but you can use your own customized image of the system if you need it.

When downloading, you will be prompted to select virtualization software, in this case VirtualBox (note: Please install VirtualBox in advance), which is free and lightweight.

2. Initialize the project

Go to my new Project directory ~/Code/Python/ Vagrant-project and perform the Vagrant init Hashicorp/Precise64 initialization.

Finally, start the virtual machine directly with the command Vagrant up

Once the virtual machine is started, you can SSH directly into the virtual machine using Vagrant SSH. Windows can only use remote login software 127.0.0.1:2222, such as Xshell, or use Tools -> Start SSH Session).

In this image, Python 2.7.3 is built in, which is sufficient for demonstration purposes only.

The /vagrant/ directory in the virtual machine corresponds to the project root directory on your host

If you want to add more folder mappings, edit the Vagrantfile file and, before end, add the following line

  config.vm.synced_folder "/Users/MING/src", "/srv/website"
Copy the code

Vagrant Reload is then performed

3. The configuration PyCharm

PyCharm is the most professional Python IDE, and it also provides excellent support for Vagrant. But before you use it, you need to configure it.

First, make sure your Vagrant plugin is installed

Then, configure the Information for Vagrant in Tools -> Vagrant

Finally, add the Python Interpreter from the Vagrant virtual machine in Project -> Python Interpreter

After configuration, whether in the Setting

The Python interpreter you see in the project interface is Python from Vagrant

In such an environment, all Python project files you create will be synchronized to the/Vagrant/directory in the Vagrant virtual machine. When you run Python projects locally, you are actually running in the Vagrant virtual machine.

If your Python project relies on a large number of components to run, you can install them all in the Vagrant virtual machine, package them as an image, and send the image and project (including the.Vagrant folder and Vagrantfile) to your colleagues. They will soon have a stable operating environment for their projects.


The PDF version of PyCharm Chinese Guide has been compiled

The document itself is completely open and free. If the document is useful to you, please give it a thumbs up. Your support and recognition mean a lot to me.

For offline reading, please click this link to download:

Mac version “PyCharm Chinese guide v2.0” : wws.lanzous.com/iJPIvner86d

PyCharm Chinese Guide V2.0 for Win: wws.lanzous.com/iG3yfne