An error occurred when running the code in VScode: [% matplotlib inline^ SyntaxError: invalid syntax]

-----------------------------------Aspiration should be lofty and down-to-earth--------- --------------------------- Cheng_Qichen

1. Problems

Running the code about OpenCV in VScode found an error:

import cv2
from matplotlib import pyplot as plt 
#%matplotlib inline 
image = cv2.imread("c.jpg")
plt.figure(figsize=(10,10))
image_rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
plt.imshow(image_rgb)
plt.show()

报错:
% matplotlib inline
^
SyntaxError: invalid syntax

Two, solve the problem

1. The first method:

#%matplotlib inline 

Comment out %matplotlib inline
Add the code at the end of the code:

plt.show()

2. The second method:

Run the code in Anaconda

import cv2
from matplotlib import pyplot as plt 
%matplotlib inline 
image = cv2.imread("c.jpg")
plt.figure(figsize=(10,10))
image_rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
plt.imshow(image_rgb)

Three, pay attention

The same problem may occur in Pycharm,
and the solution is the same

4. Inspirational words

When we become adults, we no longer have the freedom of childhood. We must always be responsible for what we do. Every step we take has attracted the attention of more people. Life is no longer entirely our own, but we have to take it step by step. Carry forward. Whether you are comfortable or complaining, you can only bear it silently, learn to change yourself, learn to adapt to the environment, and strive to become the strongest person in life. Maybe you can make yourself a little more free and less lonely. Gradually, friends have lost a lot of contact, colleagues have more competition, life has been mixed with a lot of hypocrisy, and we have put on different cloaks... But we are powerless to change. When we grow up, we will basically have our own home. Hard work and hard work, the slogan you shout is for the family, for the children, no longer for your so-called ideals, dreams, will eventually be defeated by reality, cruelty is no longer an experience of life, but more like the end of life. The older I get, the more lonely and confused I become; drinking in the past may be because of interest, but drinking now may be the so-called so-called drinking to drown my sorrows. The heart is not in the same place, and it can no longer be found. The lost color has become a blank.

Life is short, I learn Python!

V. Summary

Thank you for watching, supporting the editor, thank you for your company for many years!

Guess you like

Origin blog.csdn.net/CHENG15234944691/article/details/123814449