PyCharm replaces pip source, module installation, PyCharm dependency package import and export_pycharm modifies pip source

1. Pycharm replacement installation source
After downloading and installing Pycharm, a very important issue in the actual programming development process is to add third-party libraries. However, Python’s default source network The speed is a bit slow, so what we often need to do is to change the Pycharm installation source.
In the current latest version (version 2022.03) of Pycharm, the process of replacing the installation source is as follows:

First, at the beginning of the project, click on Python Packages below, and then click on the small gear in the upper left (note not the small gear in the upper right). The process is as follows:Insert image description here

In the pop-up page, we click the plus sign, as shown below:Insert image description here

After that, we can enter the commonly used download sources in China. I use the source of Alibaba Cloud, as shown below:

Insert image description here

- Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple
- Alibaba Cloud: http://mirrors.aliyun.com/pypi/simple/
- University of Science and Technology of China: https://pypi.mirrors.ustc.edu.cn/simple/
- Douban: http://pypi.douban. com/simple/

Note: Some packages can only be downloaded using pip default source

Downloading from domestic sources such as Tsinghua Source is very fast, but after modifying pip's default mirror source, some packages may only be available from the default source. You can only temporarily use the default source installation: pip default mirror address:

https://pypi.org/simple

Install modules from a specified mirror source

pip install <module> -i https://pypi.org/simple
pip install <module> -i https://pypi.tuna.tsinghua.edu.cn/simple

2. Add third-party libraries to Pycharm

Next, we need to install third-party libraries.
In the Pycharm page, we click File, and then select "Settings" in the pop-up drop-down box, as shown below:

Insert image description here

3. Pycharm adds third-party library error resolution

However, this installation method sometimes fails, especially when the installation source is changed. The installation failure page is as follows:

Insert image description here

At this time, we can open the details of the installation failure, and the results are as follows:

Insert image description here

The reason why this happens is mostly because our customized installation source cannot be verified. In order to solve this problem, we can copy the code in the above prompt. Then open the local cmd window and execute the above code,

Note that we need to add at the end of the code

--trusted-host mirrors.aliyun.com

Only in this way can the installation be successful.

The result looks like this:

Insert image description here

We can go back to the previous page and find that our third-party library has been installed successfully, as shown below:

Insert image description here

PyCharm dependency package import and export methods

Enter in the PyCharm terminal:

1. Export dependent packages to the requirements file

pip freeze > requirements.txt

2. Import dependent packages from the requirements file

pip install -r requirements.txt
If you need permanent access to the latest professional version of PyCharm, scan the QR code to get it for free. There are only a few spots left.

Guess you like

Origin blog.csdn.net/2301_76161259/article/details/134942242