Home  >  Article  >  Backend Development  >  Detailed explanation of how to configure virtual machines in Pycharm

Detailed explanation of how to configure virtual machines in Pycharm

Y2J
Y2JOriginal
2017-05-13 13:36:144180browse

This article mainly introduces in detail the seventh part of the most complete Pycharm learning tutorial, Python shortcut key related settings, which has a certain reference value. Interested friends can refer to

imagination In such a situation, you operate your project on one platform, but you want to complete and run it on another platform. This is why Pycharm has done a lot of work to support remote debugging.

Running a project on a virtual machine mainly includes the following steps:

(1) Define a virtual framework define a virtual box

(2) You need to configure a remote interpreter under the virtual framework configure a remote interpreter

  (3) Load the current project in the remote console launch your script in the remote console

1、Preparation

Make sure your Pycharm already has the following environment:

(1) Install Oracle's Virtual Box

(2) Vagrant is installed

(3) Add these executable files to the vagrant.bat file under the Vagrant installation file in the environment variable , this Part of the work should be completed automatically by the installation program

The VBoxManage.exe file under Oracle's VirtualBox installation file.

Make sure Pycharm's

Vagrant

plug-in is available: click the Settings button in the main toolbar, open the Plugins page in the settings dialog box, and display that the plug-in is available by default:

At this point, the preparation work is completed and officially begins.

2. Create a virtual virtual box

In the settings dialog box (click the settings button on the main toolbar), click the Vagrant interface, and then enter the Execution file path and instance path.

If the framework has been pre-defined, the above options will appear in a

drop-down list

, just select one from it:

If there is no suitable virtual box currently, you can add one by clicking the green plus sign, enter the framework name and download address:

Click OK, Pycharm starts Automatically download the VM template:

# At this point you have created a new virtual box and added it to the current environment.

Note the

Vagrant

command under the Tool menu. This command is associated with the standard Vagrant behavior. Once the Vagrant box is created, it needs to be initialized under the project stub. Click

Tools | Vagrant on the main menu,

SelectInit in Project Root:

Select the Vagrant box you want to initialize :

The corresponding Vagrantfile file will be created at this time, which can be changed according to requirements:

Initialization completed After that, execute the vagrant up command (select the

Up

command in the Vagrant menu):

## Pycharm will automatically run vagrant up

command, and display the output results on the console interface:

3. Configure the remote interpreter on the virtual machine

Open the settings dialog box again (click the settings button on the main toolbar) and select the Project Interpreter page. Here you can select a corresponding interpreter from the drop-down list, but if there is currently no interpreter available, we You need to click Configure Interpreters to customize one:

At this time, the Python Interpreters interface will open, click the green plus sign to select a remote Interpreter:

In the Configure Remote Python Interpreter dialog box, server configuration is required. These settings can be set manually or imported from an already defined Vagrantconfiguration file. Here we choose the second method. Click the Fill from Vagrant configuration button, and the relevant settings attribute value will be automatically filled in based on the content of the configuration file:

In order to confirm whether the configuration is successful, click Click the Test connection... button:

Set it as the default interpreter:

From now on we can run all script projects on the VM virtual machine:

Next we log in to the virtual box through SSH.

4. Link to SSH terminal

Why do you need to log in? Because Pycharm requires you to do this.

Select Tools | Run SSH Terminal in the main menu. If you have defined more than one host, select the one you want to establish a link to (we choose the remote interpreter here) ):

Observe the console running information of the Run tool window:

Now you can interact with the virtual box For direct interaction, first we confirm whether your project directory is fully mapped. Just observe vagrant's default shared folder information:

Next run an available script file, such as Solver.py:

Done.

【Related Recommendations】

1. Special Recommendation: "php Programmer Toolbox" V0.1 version download

2. Python free video tutorial

3. Object-oriented video tutorial

The above is the detailed content of Detailed explanation of how to configure virtual machines in Pycharm. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn