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

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!

主站蜘蛛池模板: 贵港市| 新疆| 淮阳县| 鸡西市| 蚌埠市| 保亭| 宜兰县| 洛川县| 墨玉县| 屯昌县| 永嘉县| 玉环县| 凭祥市| 巴彦县| 裕民县| 登封市| 深泽县| 揭西县| 岢岚县| 商水县| 札达县| 寿宁县| 武山县| 汶川县| 祁东县| 右玉县| 利津县| 明光市| 桃江县| 怀化市| 嘉黎县| 昭通市| 宁河县| 永济市| 盐城市| 泰来县| 阜新市| 樟树市| 上栗县| 孙吴县| 南汇区|