How do I load a Python module given its full path?
Note that the file can be anywhere in the filesystem where the user has access rights.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s have
MyClassinmodule.namemodule defined at/path/to/file.py. Below is how we importMyClassfrom this moduleFor Python 3.5+ use (docs):
For Python 3.3 and 3.4 use:
(Although this has been deprecated in Python 3.4.)
For Python 2 use:
There are equivalent convenience functions for compiled Python files and DLLs.
See also http://bugs.python.org/issue21436.