Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining consistent (and legal) import style in Pycharm

My Pycharm is autogenerating imports of this form: from submodule.subsub import myfunction. The root module , under which submodule sits, is missing in this import command. Yet this runs OK on my machine (Ubuntu).

In my colleague's machine (Windows; I don't know if that makes a difference), Pycharm correctly generates from root.submodule.subsub import myfunction, which runs OK on my machine too.

How do I get Pycharm to generate the full path on my machine? How do I get Python and Pycharm to correctly tell me that the abbreviated path is an error?

like image 324
Joshua Fox Avatar asked Dec 10 '25 15:12

Joshua Fox


1 Answers

The issue is due to the fact Pycharm does not detect the correct folder as the root of the project.

You can define any folder as the Root by right clicking on it going to Mark Directory as -> Sources Root. The folder color will change from grey to blue. Changing the Root directory changes the behavior of these auto-generated statements in my experience.

like image 148
Eskapp Avatar answered Dec 13 '25 05:12

Eskapp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!