Project wide import of library Python

Answered

I'm building a PyCharm Plugin which adds several capabilities such as support of a custom language.

The user writes Python code in multiple files and needs to use some stubs as a part of the development.

My current solution is adding module x to the project, the module has the stubs and then the users need to add from x import mystubs at the beginning of each file. Then, when they want to write something with them they use mystubs.stub(input).

Is there a way to globally import (perhaps in the project settings) the stubs module? The end goal is that the users would be able to write mystubs.stub(input) without any errors, and without them having to add from x import mystubs at the beginning of each file.

Thank you, Shachar

5 comments
Comment actions Permalink

Hi Sergey,

It's not really plugin-specific. 
The question in hand is how can I import a package using PyCharm to be used globally in the project.

Best,
Shachar

0
Comment actions Permalink

I am afraid there is no such option to add import statement to the first line of all new files. We have an Auto Import feature https://www.jetbrains.com/help/idea/creating-and-optimizing-imports.html which allows to import packages automatically when writing code.

0
Comment actions Permalink

Hi Sergey,

Perhaps an option to extend Python's builtin objects?

Thanks,
Shachar

0
Comment actions Permalink

Ooops, sorry, I forgot to mention File and Code Templates (https://www.jetbrains.com/help/pycharm/using-file-and-code-templates.html). This is how you can actually add import statement to all new python files by default.

0

Please sign in to leave a comment.