Issue
I am working on updating a series of python 2.7 plugins to python 3.10 that get loaded into the software individually. Below is an example of how the python 2.7 plugin is organized.
ProjectDir
- Plugin1
__init__.py
- Plugin2
__init__.py
- Plugin3
__init__.py
- Common
- CommonFunctions.py
All three of the plugins use functions out of the CommonFunctions.py file. When I have updated the import statements for the three plugins to
from ..Common.CommonFunctions import Example1
I get the exception:
ImportError: attempted relative import beyond top-level package
Based off of my research this is due to the Common directory not being in the same directory as the init folder (or one of its subfolders). Is there a way to solve this issue without copying the Common directory to each plugin?
I have verified that when I do copy the folder over the issue is resolved. However, that is not a desired solution.
Solution
It would just be from Common.CommonFunctions import ...
, assuming ProjectDir
is on sys.path
as itself and is not a package.
(If ProjectDir
was a package, the original relative import would work anyway.)
Answered By - AKX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.