How can I import my own package in Anaconda?
To import your own package, you need to first add the directory where the package is located to sys.path, and then use the import statement to import the package or module.
Assume your package name is “mypackage”, the directory structure is as follows:
mypackage/
__init__.py
module1.py
module2.py
You can import the “mypackage” package using the following code:
import sys
sys.path.append('/path/to/mypackage')
import mypackage.module1
import mypackage.module2
Then you can use the modules in the “mypackage” package. For example:
mypackage.module1.my_function()
mypackage.module2.my_class()
At the same time, specific functions or classes can also be imported using the from-import combination.
from mypackage.module1 import my_function
from mypackage.module2 import my_class
my_function()
my_class()