If the script directory is not available (e.g. To get your current directory back into sys.path there is in fact no better way than putting it there. 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…?) import (which means “import from the same package I got imported from”) doesn’t work. 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. Is there a better way?įails with this error: ValueError: Attempted relative import in non-package I want to import it in the interpreter (v2.5), but sys.path does not include the current directory. I’m developing/testing a package in my local directory. Question or problem about Python programming:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |