PyCharm replaces pip source, module installation, PyCharm dependent package import and export

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


First, when the project starts, click Python Packages below, and then click the small gear on the upper left (note that it is not the small gear on 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 source in China. I use the source of Alibaba Cloud, as shown below:

insert image description here

- Tsinghua University: 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 the pip default source

The download speed is very fast using domestic sources such as Tsinghua source, but after modifying the pip default mirror source, some packages may only be available in the default source. Only temporarily use the default source installation: pip default mirror address:

https://pypi.org/simple

 Install a module 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. Pycharm adds third-party libraries

Next, we need to install third-party libraries.
On 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 to install, especially when the installation source is replaced. The installation failure page is as follows:

insert image description here

 At this time, we can open the detailed information of the installation failure, and the result is as follows:

insert image description here

 The reason why this happens is mostly because our custom 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 then 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 page just now, and we can find that our third-party library has been installed successfully, as shown below:

insert image description here

 

PyCharm depends on package import and export methods

Enter in the terminal of PyCharm:

1. Export the dependency package to the requirements file

pip freeze > requirements.txt

2. Import dependent packages from the requirements file

pip install -r requirements.txt

Guess you like

Origin blog.csdn.net/qq_42672770/article/details/130388423