About the experience of installing third-party packages in Google Colab editor using Python

foreword

In the past, I only knew that Jupyter notebook did not pay attention to Google and has the same product. Recently, I have done a series of operations on machine learning. Let me talk about installing third-party modules. Use xxx as the !pip install XXXpackage name to install it.

Encountered pit

The first is the Python version problem. You may encounter the problem of importing an error after installation, telling you that the package does not exist, but you can find that !pip listyou have already installed the package by checking the package installation list, or you can use it directly !pip show package_name. Check the name, and found that the packages are all installed. Later,
I thought that my Python file was not in the same folder as the package, and I used the import sys module to switch the directory and found that there was still an error. There is no corresponding package.

Solution

First of all, make it clear that google colab !pip install XXXis installed globally, that is to say, it can be used globally. The first part is to judge whether your Python version is compatible with this package. If it is not compatible, you need to use it to !apt-get install python3.9upgrade the version. If this does not solve your import package If there is a wrong problem, you need to restart the operating environment, just like a computer with a win system that needs to be restarted to fully use it after installing a certain software.
insert image description here
You can solve this problem by finding the restart code execution program in the code execution tool.

Guess you like

Origin blog.csdn.net/weixin_36662706/article/details/130502738