Home > Net >  VScode order of python imports: how to force tensorflow to import before keras?
VScode order of python imports: how to force tensorflow to import before keras?

Time:01-24

I am importing several libraries in a .py file using VScode.

somehow it always orders the imports when I am saving the file. It is important for me that a certain order is maintained, for example:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0" 

should be before:

import tensorflow.compat.v1 as tf

which in turn should be before

import keras.backend as K
import keras

but even if I press option shift o, this order is lost after saving.

How can I force the order I need in this case, while generally keep VScode setting the order alphabetically?

CodePudding user response:

You need to disable Format on Save in VSC's settings.

  • Click Files > Preferences > Settings
  • Type format in the search box
  • Disable Format on Save
  • Related