There are two python editors how to install gdal and rasterio packages

Open the specified python version in cmd

When two versions of python compilers are installed on our computer (although one is enough for most people, but because I study remote sensing, I often use arcgis, and the python2.7 version compiler that comes with it is too old , so I installed python3.8 again), which led to the fact that when python is entered in cmd, version 3.8 is opened by default, and when the package is downloaded with pip, it is also installed in python3.8 by default. Today I will share some of my little experiences.
1. Right-click the "Start" menu and click "Run", enter cmd, and click OK to open the command prompt interface. Let's enter python first, and you can see that python3.8.3 is opened. Type exit() if you want to exit python.
insert image description here
insert image description here

2. Like me, I also installed a python2.7, which is the compiler that comes with arcgis (as shown below). Enter py -2 or py -2.7 in the cmd interface to open the python2.7 version. Similarly, py -3 or py -3.8 can also open python3.8 version, and other versions are similar. Note here that after entering py -2, you will enter the python compiler, and all subsequent inputs must conform to the grammatical rules of python. If you want to re-enter the python3.8 version, you need to exit python2.7 first (enter exit() ), and then enter py-3 (see image below).
insert image description here
insert image description here
3. If a certain version of python is installed in your computer, but it does not open when you enter py -x, it may be that the path of the compiler does not exist in the path of the environment variable. The role of path is: when we input instructions, the computer will go to these paths to search for the programs that need to be run. If there is no python compiler path in the path, it may not be able to search, so it cannot be opened (this is my understanding, may not be correct).

The way to view environment variables is: right-click "My Computer", click "Properties", "Advanced System Settings", you can reach the "System Properties" interface, click "Environment Variables", double-click the path in the user variables, that is Can view and edit paths. The user variable here refers to the variable set by the user of the current account. If it is changed to another account, it will be different. The system variable means that no matter which account uses this computer, there are these variables.

Like me, you can open it by adding the path where the python2.7 version is located.

insert image description here
insert image description here
insert image description here
4. It is also worth noting that the computer with the path on the top of the path will be searched first. I still remember that when I entered python before, I opened the python3.8 version. That is because the previous python3.8 path was in the 2.7 version. Above, and now I put the path of version 2.7 on it, then enter python in the cmd interface and you will find that the
version opened by default is python2.7, are you surprised, haha! It means that you want to open the specified version of python, you can also put the path of the version above (but this is too much trouble).
insert image description here

Install the gdal and rasterio packages

1. The gdal package is a very powerful package for processing spatial data. It may be necessary for those who study geographic information systems and remote sensing. The rasterio package is a package developed on the basis of the gdal package. It is mainly used to process raster data modules. The rasterio package is relatively simple to use. Next we will see how to install them.
2. I thought it would be the same as before, just use pip install gdal, but I couldn’t download it, so I went to the Internet to download the whl files of the gdal package and the rasterio package (both packages are in this website, and the package name is Alphabetically sorted, easy to find). We need to find a package that suits our python version and computer. 3.1.2 in the package name indicates the version of the package, cp38 indicates that this package is suitable for python3.8 version, and win32 indicates the windows system (don’t make a mistake here, it does not represent a 32-bit operating system! 32-bit and 64-bit Both are included), and the other win_amd64 indicates that the computer CPU is 64-bit (the python2.7 that comes with arcgis needs to download the amd64 version to install it, and I don’t know why, you can try both). Here I downloaded the package in the red circle (because my python is version 2.7 and 3.8) and put it on the desktop.
insert image description here

insert image description here
3. Install the downloaded package with pip. I first install the 3.8 version of the package. First, switch the working directory to the desktop (because the installation package is placed on the desktop), the command is cd C:\Users\Administrator\Desktop, and then enter pip3 install GDAL-3.1.2-cp38-cp38-win32.whl, that is can be installed. Here pip3 refers to install with pip in python3.8 version. After installation, it can be used for version 3.8. When inputting commands, you must also enter the .whl suffix.
Similarly, pip3 install rasterio-1.1.5-cp38-cp38-win32.whl, here we can see that he also installed some other packages at the same time, this is because the rasterio package also depends on some other packages, if you do not Install, it will be downloaded and installed automatically.
The python2.7 version is installed. Similar to the above, just change pip3 to pip2 and change the package name to a new name.
insert image description here
insert image description here
4. Check whether the package is installed successfully. Enter py -3, enter python3.8, and enter import gdal, rasterio. If no error is reported, the installation is successful.
insert image description here
5. If you want to uninstall a certain package in the future, for example, I want to uninstall the gdal package in python3.8, pip3 uninstall rasterio can uninstall it.
insert image description here
To sum up, this time I will share with you how to enter the specified version of python, modify environment variables, download gdal and rasterio packages, install and uninstall packages with pip, and hope to help you. This is my first blog post, so please correct me if I am wrong.

Guess you like

Origin blog.csdn.net/weixin_42999968/article/details/107856525