by gigatexal · 5y ago · 0 comments
But if you're not and you're using vscode, this is the relevant thingy to do to get vscode to play nice: https://code.visualstudio.com/docs/python/environments#_use-...
You would then `import .foo`
> You would then `import .foo`
The `import .foo` is a syntax error, and `from . import foo` does not work for scripts [1].
The basic `import foo` works if the directory is on your PYTHONPATH. That will be the case if you run `bar.py` as a script.
It gets more difficult if you want to separate scripts and importable modules into separate sibling directories (bin vs lib). You can't use relative imports to get around that, you need to use a virtualenv (or manual PYTHONPATH wrangling).
Python now ships with the venv cli tool.
If you point your editor to the python interpreter in the venv, it will detect everything automatically.