cartopy installation problem record

Record the problems encountered by pip installation cartopy:

The origin of all problems: the official did not provide whl files, and at that time https://www.lfd.uci.edu/~gohlke/pythonlibs/ website made an error, this is the only mirror website that provides whl files (but it is now restored ready to use)

In order to solve the problem, I re-learned how to install the pyhton library from the source code, so I downloaded the cartopy source code, and prepared to compile and generate a whl file by myself, but there were many problems.

The main problem is: cartopy relies on two third-party libraries when compiling: geos and proj, and these two are c/c++ language libraries, so you need to download and compile these two libraries first.

How to compile the c/c++ library. Fortunately, I have a little foundation. I used cmake to compile the geos library without any risk;
however, I encountered problems compiling the proj library. When compiling, proj relied on sqlite, tiff and other libraries ( That's right, there are more than 2 libraries), after I downloaded and compiled all the dependent libraries, I configured the environment again, and finally compiled the proj.

Now the dependencies of cartopy are all compiled, and then I thought it could be installed smoothly, but there was a problem again. I did not find the compiled geos and proj in the setup.py file, but this is a small problem. I directly put the location of the geos and proj libraries Specify it in the code, and happily run python setup.py bdist-wheel.
At this time, I gave me another big trick. I couldn’t find the vc++ compiler when compiling. I usually use mingw. In order to compile a python library, I need to install visual studio? ? ? That is absolutely impossible, so I checked and found that the following 2 lines can be added to setup.cfg, and then compiled with mingw

[build_ext]
compiler=mingw32

At this time, there was a problem with the compilation. There was a division by 0 operation in trace.cpp, so I changed it, and finally compiled successfully, and got the whl file of cartopy.

But the matter is not over. When I installed cartopy and tried it with an example, I found that the DLL file could not be found, and I couldn't solve it for a day. I don't want to do it anymore, so I use the basemap to do the task first. The matter of cartopy was put aside later.

After 2 weeks, I remembered this matter again, and I worked on it for a few hours, but it still didn't work out. I accidentally found that the website https://www.lfd.uci.edu/~gohlke/pythonlibs/ has been restored, so I downloaded cartopy from above, and there was an error when running the example. At this time, I realized that things seemed not simple. Shapely was uninstalled and downloaded from the above website, which finally solved the problem.

Only then did I find that the geos_c.dll provided by shapely and the proj.dll file provided by pyproj were not compiled by myself, and these two were not compiled with mingw, so it may lead to the two dependencies of the cartopy root compiled by myself The library is not compatible, and the download from that website may be compiled with a vc++ compiler, so there will be no problem. . .

After tossing for a long time, I finally solved the problem by downloading from the website [crying]

Finally, put these libraries in the Lanzoup cloud network disk https://ajream.lanzoup.com/i9KWk0zble7e to avoid problems with the above website

Guess you like

Origin blog.csdn.net/m0_46079750/article/details/131255162