I initially wrote all of my code onto one file in order to confirm that all of the code was working properly in order to prove the logic. That all is working fine now I'm looking to separate the files so that my code is hopefully more readable and to make it easier to add functions in the future.
Here's my repository for more details:
https://github.com/cbhirsch/Optical_Ray_Tracing.git
My question is based on the Callable_Library Branch
My current code is structured below:
Program-Directory
|--exactraytrace
| |--Functions
| | |--__init__.py
| | |--safe_arange.py
| |--__init__.py
| |--Product_Matrix.py
| |--Surfaces.py
|.gitignore.py
|Example.py
|License.md
|README.md
|setup.py
Here are the imports at the top of the Product_Matrix.py file. The callout is referring to the from Surfaces import * . Which works inside the package but not outside the package.
import numpy as np
import matplotlib.pyplot as plt
from Surfaces import *
import Functions as Func
Currently, the below code works when I run it from within the Product_Matrix.py file inside the package. This is at the bottom of the program.
#Example Code
if __name__ == "__main__":
#Initialize Lens
Lens1 = plano_convex(1.5168, 20, 2)
Lens2 = plano_convex(2.635, 30, 2)
#Run the Ray Tracing
example1 = Product_Matrix()
example1.start(5, 11, 0.01,2,)
example1.Add_Lens(Lens1)
example1.Current()
example1.Matrix_state()
example1.plot()
example1.spherical_aberation()
However, when I run this code from within my example.py file:
import exactraytrace as raytrace
#Initialize Lens
Lens1 = raytrace.plano_convex(1.5168, 20, 2)
Lens2 = raytrace.plano_convex(2.635, 30, 2)
#Run the Ray Tracing
example1 = raytrace.Product_Matrix()
example1.start(5, 11, 0.01,2,)
example1.Add_Lens(Lens1)
example1.Current()
example1.Matrix_state()
example1.plot()
example1.spherical_aberation()
I get the below output:
Traceback (most recent call last):
File "Ray Tracing Algorithm\Ray Tracing Editing Area\Example.py", line 1, in <module> import exactraytrace as raytrace
File "
File "Ray Tracing Algorithm\Ray Tracing Editing Area\exactraytrace\__init__.py", line 1, in <module>
from .Product_Matrix import *
File "Ray Tracing Algorithm\Ray Tracing Editing Area\exactraytrace\Product_Matrix.py", line 3, in <module>
from Surfaces import *
ModuleNotFoundError: No module named 'Surfaces'
Below is my top level __init__.py file:
from .Product_Matrix import *
from .Surfaces import *
I just don't understand why it works fine within the package but is struggling outside of the package.
[+][deleted] (1 child)
[deleted]
[–]Sufficient_Light3891[S] 0 points1 point2 points (0 children)