Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

536
Vistas
Pycharm auto relative imports

Whenever you use autoimport provided by PyCharm it generates an absolute path import. i.e.

from my_package.my_subpackage import my_thing

instead of

from .my_subpackage import my_thing

Is there a setting to use relative imports instead of absolute ones when importing a python package?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It appears currently there is no way to change the import style for auto-import feature to use relative imports. The only style changes you can make to import statements are how the absolute imports are structured:

enter image description here

(The Jetbrains/PyCharm settings search functionality is excellent by the way).

The same thing happens when refactoring, it's definitely an option I'd like to see added.

over 4 years ago · Santiago Trujillo Denunciar

0

It will be possible starting with 2019.3 https://youtrack.jetbrains.com/issue/PY-6054 Note, that it will not do the relative import automatically if there are no other relative imports in that file yet. There is also an action to convert the existing absolute import to relative: enter image description here

over 4 years ago · Santiago Trujillo Denunciar

0

I would advise against relative in general, you can refer to this question: https://softwareengineering.stackexchange.com/a/159505

Also, you can check official pep8 specs https://www.python.org/dev/peps/pep-0008/

Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path):

From my personal experience it turns out that they sometimes poorly integrate with Pycharm IDE when there's more complex package layout breaking test running through Pycharm. I suppose there might be some issues in other tools too.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda