Home > Article > Backend Development > How to make pydev in Eclipse skip these compilation errors for this purpose
#1. The following program is the beginning of a tensorflow neural network code, used to illustrate how to simply make TF version compatible and how to ignore compilation errors in pydev to run
#2. Because the TF version is not yet stable, the differences between different versions are not small. There are many Python programs of different TF versions such as 0.10.0, 0.11.0, 1.0.1, etc. on github, so your local environment is the same. It is easy to find problems one after another by using py and tf.
#3. The following is a simple solution. Use the try...except structure to make tf version compatible. This way you don't have to modify every function in the code, and do some judgment and conversion during activation. That’s it. For example, in the following judgment of the "scalar_summary" and "concat_v2" functions, if the old and new TFs are different, compatibility can be made here, while the subsequent main body of the program remains basically unchanged.
#4. But we encountered a problem. This try...except structure will report an error (red wavy line) in eclipse+pydev. We can easily think that this is the pydev compiler to help us. Processing, it detects the problem and prompts it with a red wavy line of error. As long as we enter the menu "windows-->Perferences-->PyDev-->Editor-->code anaylsis", adjust the processing level in the "undefined" and "import" tab panels on the right, change " Just change error" to "warning". Finally, select the "abc.py" file in eclipse, right-click the menu and select "pydev-->code analysis" to recompile and analyze the codes. The red wavy line error will disappear and the entire program can be run.
======================================== ===
from tensorflow.python.framework import ops
from utils import *
import tensorflow as tf
import math
import numpy as np
# The following try except handles TF version compatibility issues through exceptions! ! !
#Here is an idea to be compatible with the differences between the old and new formats of TF. It is simple but practical!
try:
#import tensorflow as tf
#Older TF format;
image_summary = tf.image_summary
scalar_summary = tf.scalar_summary
histogram_summary = tf.histogram_summary
merge_summary = tf.merge_summary
SummaryWriter = tf.train.SummaryWriter
except:
#The following is the new format of the newer TF. If the OLD format in TRY fails, the new format will be used;
image_summary = tf.summary.image
scalar_summary = tf.summary.scalar
histogram_summary = tf.summary.histogram
merge_summary = tf.summary.merge
SummaryWriter = tf.summary.FileWriter
if "concat_v2" in dir(tf):
def concat(tensors, axis, *args, **kwargs):
return tf.concat_v2(tensors, axis, *args, **kwargs)
else:
def concat(tensors, axis, *args, **kwargs):
return tf.concat(tensors, axis, *args, **kwargs)
#....The subsequent logic code is ignored and has nothing to do with the topic of this article...
The above is the detailed content of How to make pydev in Eclipse skip these compilation errors for this purpose. For more information, please follow other related articles on the PHP Chinese website!