no module named cv2, numpy, xxx super complete solution

General solutions can be found on the blog:
https://blog.csdn.net/ALiLiLiYa/article/details/126988014

Case

If the above is still not solved, you can refer to the following steps:
For example: The following files obviously exist in the folder, but an error is still reported . Then it may be caused by missing environment variables.

 No module named 'torchvision.edgeailite'

Solution 1:

export PYTHONPATH=:$PYTHONPATH:yourfile/path/edgeai/torchvision

Note:
Replace yourfile/path/edgeai/torchvision with your file path

Solution 2

Actively add environment variables

import sys
sys.path.append('/path/to/my/module')

Replace '/path/to/my/module' with the path to your exact file

Summarize:

sys.path Note 1

In Python, sys.path is a list containing the paths that the Python interpreter searches when importing a module. By default, sys.path will contain the following paths:

  • Empty string (indicates the current directory)
  • Python installation directory
  • The path specified in the PYTHONPATH environment variable
  • Operating system specific directories

If you want to add a custom path to sys.path, you can use the sys.path.append() method. This method accepts a path as a parameter and adds it to the end of sys.path. For example:

import sys
sys.path.append('/path/to/my/module')

In this example, we add the path /path/to/my/module to sys.path. This will cause the Python interpreter to also search this path when importing modules. This is useful for importing self-written modules or third-party modules.

Note that the order of sys.path is important. The Python interpreter searches for modules in the order they appear in sys.path. Therefore, if you also have a module with the same name as the Python standard library, Python may find the module you wrote first rather than the module in the standard library. So you need to make sure that the paths you add to sys.path do not conflict with module names in other existing paths.

Note 2PYTHONPATH

In this command, you try exportto add a path to an PYTHONPATHenvironment variable using the command. PYTHONPATHis an environment variable that tells the Python interpreter where to search for modules. In this command, use is used $PYTHONPATHto reference the current PYTHONPATHvalue and use is used :to separate different paths.

PYTHONPATHHowever, this command has a bug: no path is specified before the colon when adding the new path to . The colon is actually used to separate different paths, here it means PYTHONPATHadding the current one before the new path. Therefore, this command should be modified to:

export PYTHONPATH=$PYTHONPATH:/yourfile/path/edgeai/torchvision

Doing this will be /yourfile/path/edgeai/torchvisionappended to the end of the current PYTHONPATHpath, causing the Python interpreter to also look for this path when searching for modules.

Please note that this command is only valid within the current shell session. If you want this environment variable to be set every time you start the shell, you can add this command to your shell configuration file (such as ~/.bashrcor ~/.zshrc).

Hope this information is helpful to you. If you have further questions, please feel free to ask.

Guess you like

Origin blog.csdn.net/ALiLiLiYa/article/details/135125810