Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set up Virtual Environment and change Image in pycharm

Shulou Source: shulou.com Published: 2022-06-03 18:25:57 10月19日 Update

Editor to share with you how to set up a virtual environment and change the image of pycharm, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Set up a virtual environment for the project

The virtual environment of Python can be similar to the Tomcat container in Java.

Its main function is to create an independent running environment for different projects. in the virtual environment, each project has its own package, which has nothing to do with other projects. * * there can be different versions of the same package in different virtual environments. * and there is no limit to the number of virtual environments.

After you create a Python project, a virtual environment named venv is created by default. Of course, we can also create our own virtual environment with the following command:

Method 1 to create a virtual environment

The following command sets up a virtual environment named test_venv for the project python_demo_1.

Python3-m venv test_venv

Method 2 of creating virtual environment

To create a virtual environment through the virtualenv command, first install the virtual environment tools through the pip command

Pip install virtualenv

Then, we create a virtual environment called "evn_demo"

Virtualenv evn_demo

Activate the virtual environment

To activate the virtual environment under windows, you only need to go to the Scripts directory of the virtual environment that needs to be activated, and then execute the activate.bat command. Similarly, you only need to execute the deactivate.bat command to exit the virtual environment. As shown in the following figure:

The command to activate the virtual environment under Linux is:

Source env_demo/bin/activate

Exit the virtual environment

Deactivate does not create a virtual environment through commands

The method is File---- > Settings- > Project:python_deom_1 (project name)-> Project Interpreter---- > Add Local

Search for third-party libraries

A Python project always relies on a lot of third-party libraries, for example, now we want to introduce the websocket library, but do not know the version, what should we do? We can also search on pycharm as follows:

File---- > Settings- > Project:python_deom_1 (Project name)-> Project Interpreter Click the * * + * * sign in the list of all third-party libraries.

As shown in the figure below, search for the package of websocket. The latest version found is 0.2.1. Then, click the Install Package button to install the package. Of course, we can also check Specify version to select other versions.

Click the Manage Repositories button to change the mirror source of the pip. Here, the official image source is changed to the mirror source of Tsinghua University

Https://pypi.tuna.tsinghua.edu.cn/simple

These are all the contents of the article "how to set up a virtual environment and change images in pycharm". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Environment command project mirror activation version different project method third party article search content button not much function can be passed name most official Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Xiaomi OPPO Reno vpn