0

Every time I need to use absolute import, for example:

from my_package.my_module import my_function

I declare my package to the $PYTHONPATH by writing down these code lines into my __ init __.py file located a the root of my package directory:

import sys
import os
sys.path.insert(0, os.getcwd())

But I find this solution totally inexpressive... Is this functionality natively supported by the Python standard library?

Martin Tovmassian
  • 1,010
  • 1
  • 10
  • 19
  • Read about venv (python3) or virtualenv (python2) and how to use virtual environements will certainly help you. – manu190466 Dec 11 '20 at 13:05
  • Thanks, but right now I'm on a legacy code. No virtualenv to help... – Martin Tovmassian Dec 11 '20 at 13:41
  • 2
    This is not related to how old your code is. Have a look at this answer : [Tired of sys.path hacks?](https://stackoverflow.com/a/50193944/4611565). It's a bit long to read but I found it very instructive ... – manu190466 Dec 11 '20 at 15:02

0 Answers0