官术网_书友最值得收藏!

Virtual Environment

PyCharm will help us create a virtual environment. We want to develop our project in its own virtual environment in order to keep it isolated. Due to this, we will have absolute control over the versions of the packages that we are going to use.

The best way to learn is through practice. Let's get our hands dirty now!

Exercise 5: Creating a Development Project in PyCharm

Before you start developing the Python application, you'll need to create a development project in PyCharm. PyCharm manages things using projects. In this exercise, you will learn how to create a new development project in PyCharm called Smilecook. You will also need to install the necessary packages for this project. Let's get started:

  1. Create the project and name it smilecook:

    Figure 2.2: Creating a project

  2. Check the project structure and ensure that the virtual environment has been created. Once the module has been created, we will be able to see the project's hierarchy on the left-hand side panel. We can see the venv folder under the project folder, which was created and activated by PyCharm. Now, when we write code under this project, it will be run in the virtual environment:

    Figure 2.3: Checking the project structure and ensuring that the virtual environment has been created

  3. Install the required packages for this chapter. To do this, create a file called requirements.txt under our project folder. Type in the following code to specify the packages you want to install:

    Flask==1.0.3

    Flask-RESTful==0.3.7

    httpie==1.0.3

  4. Use the pip command to install these packages. After that, in the Terminal tab, at the bottom of Pycharm, use the following pip command to install the packages that we specified in the requirements.txt file:

    pip install -r requirements.txt

  5. You should now see something similar in the following screenshot. Here, we can see that the packages are being installed on the virtual environment:

Figure 2.4: Installing the packages on the virtual environment

Congratulations! You have created a PyCharm project for our Smilecook application. This is the first step of you embarking on your journey as a developer!

主站蜘蛛池模板: 玛沁县| 建水县| 沂南县| 屏东市| 平昌县| 正定县| 金阳县| 沽源县| 咸宁市| 泸西县| 赞皇县| 建湖县| 会宁县| 嘉善县| 丰顺县| 西宁市| 南阳市| 大姚县| 黄龙县| 玛纳斯县| 涡阳县| 临武县| 石渠县| 南澳县| 商水县| 保德县| 东平县| 南丹县| 湘潭县| 泸州市| 汶上县| 洛扎县| 永修县| 惠东县| 宜州市| 龙江县| 张家川| 博乐市| 扬中市| 兴仁县| 正蓝旗|