【LINUX-python】PATH、sys.path、PYTHONPATH

This blog has been written very well, thanks to the blogger, I just sorted it out again.

[python] Understand environment variables and never be afraid of 3P... PATH, sys.path, PYTHONPATH - Programmer Sought

The following is my combing of python and configuring the python environment:

Python is both software and a programming language, so let's start with installing the software

1. Install python

Installing python in linux has apt-get automatic installation and source code installation (the following is just to sort out the essence of these two methods and not purely for installing python)

1.1 Linux uses apt-get to install software

The use of apt-get: The use of apt-get in linux - Makino Xingchen - Blog Garden

The default installation path of apt-get:

​​​​The default installation path of apt-get in ubuntu. Summary of installation, uninstallation and viewing methods_u013797029's column-CSDN blog_apt default installation path

1.2 Linux uses source code to install software

Multi-version installation of python and common errors (long-term update) - 流火无心- 博客园

Note that when installing from source code, you can set the installation location of your software by specifying ./config.

2. Declare the location of the python you want to use to linux

Whether it is source code installation or apt-get installation, you need to tell linux where you installed python after installation, so that linux can find your python. At this time, you can also think that if multiple pythons are installed in the system, you can also pass In this way, tell linux which one you want it to use. So how to tell linux where your python is installed? There are two methods: adding environment variables and creating soft links

2.1 Set in the environment variable PATH of the system, the python path you want to use:

Among them, the search path for executable scripts is set in $PATH, that is, when you directly enter executable scripts such as python on the command line, the system will check whether there is such a script in $PATH 

​​​​​​Linux 3 ways to add PYTHONPATH environment variables

2.2 Create a soft connection

Create python soft link in Linux

Among them, it is necessary to pay attention to:

To create a soft connection, you can use ln 

You can use ls -al or ll to view the soft connection. If you want to view the soft connection about python in detail, you can use |grep python to narrow the scope

The detailed usage of each command is as follows:

Linux ln command |

Linux ls command |

Linux grep command |

Recommended to see: Detailed explanation of linux command ll information_HELLOW, Wen Hao-CSDN Blog_linux ll

Why should a soft link be created under /usr/bin: the relationship between linux usr/bin/ and usr/local/bin, what is a soft link? _Public Account: Algorithm Siege Lion - CSDN Blog

2.3 What is the difference between soft links and adding PATH environment variables?

For details, see: Linux environment variables and soft links_huang_cheng_zhi's blog-CSDN blog_soft links and environment variables

 After sorting out how to install python manually and automatically and which python to use for the instructions, you will also sort out how to install this software. You must know that python is not only a programming software, but also a language. There will be many official packaged ones. The library file is for users to use, so how do we download the packaged library? --pip. After the download is complete, where are these libraries downloaded? Note that the python executable file and its library folder are not in the same folder, so we continue to sort out.

3. PIP

3.1 pip definition

What is pip? pip is the package manager for Python. This means it is a tool that allows you to install and manage other libraries and dependencies that are not part of the standard library.

Package management is extremely important, so since version 3.4 of Python3 and version 2.7. A must-have tool for Pythonista (Python users).

Python comes with pip in its installer, so you can use it unless you have an earlier version of Python. You can verify that pip is available by running the following command in the console:

3.2 How to use the pip installation package

Installation steps and detailed explanation of pip under linux Develop Paper

3.3 Where are the packages installed by pip installed?

pip install generally installs the dist-packages in the python directory you use by default.

Which can specify the directory when installing a package
pip install --target=d:\somewhere\other\than\the\default package_name

3.4 How to use these installed packages --import

The path of python search package is as follows:

1. The main directory of the program

2. PYTHONPATH directory

3. Standard link library directory

4. Any .path file directory

Note: The search path of the python module is set in $PYTHONPATH, not the python path

python import search path path setting pythonpath library_aaronlyt's column-CSDN blog_python search path setting

Guess you like

Origin blog.csdn.net/m0_46093829/article/details/122555289