I\'m developing/testing a package in my local directory. I want to import it in the interpreter (v2.5), but sys.path does not include the current directory. Right now I type
You can use relative imports only from in a module that was in turn imported as part of a package -- your script or interactive interpreter wasn't, so of course from . import
(which means "import from the same package I got imported from") doesn't work. import mypackage
will be fine once you ensure the parent directory of mypackage
is in sys.path
(how you managed to get your current directory away from sys.path
I don't know -- do you have something strange in site.py, or...?)
To get your current directory back into sys.path
there is in fact no better way than putting it there.
A simple way to make it work is to run your script from the parent directory using python's -m
flag, e.g. python -m packagename.scriptname
. Obviously in this situation you need an __init__.py
file to turn your directory into a package.
Inside a package if there is setup.py, then better to install it
pip install -e .