Sterncat / opticspy

python optics module
MIT License
458 stars 127 forks source link

ImportError: No module named glass #25

Open psychemedia opened 6 years ago

psychemedia commented 6 years ago

Installing in py2.7 from pip in Azure notebooks environment gives an error at first base:

!pip2 install opticspy
from opticspy.ray_tracing import *

returns:

ImportErrorTraceback (most recent call last)
<ipython-input-1-518116206b61> in <module>()
      1 get_ipython().magic(u'matplotlib inline')
----> 2 from opticspy.ray_tracing import *

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/__init__.py in <module>()
----> 1 import lens, trace, glass, draw, analysis, field, codev

ImportError: No module named glass
Sterncat commented 6 years ago

Please check again. It may fixed

2018-08-02 2:40 GMT-07:00 Tony Hirst notifications@github.com:

Installing in py2.7 from pip in Azure notebooks environment gives an error at first base:

!pip2 install opticspy from opticspy.ray_tracing import *

returns:

ImportErrorTraceback (most recent call last)

in () 1 get_ipython().magic(u'matplotlib inline') ----> 2 from opticspy.ray_tracing import * /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/__init__.py in () ----> 1 import lens, trace, glass, draw, analysis, field, codev ImportError: No module named glass — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
psychemedia commented 6 years ago

Thanks, seems to work for me now in py 2.7

However, I get an error even quicker in py3.6, which the update to the repo README suggests should work?

!pip3.6 install --upgrade git+https://github.com/Sterncat/opticspy.git
from opticspy.ray_tracing import *

returns:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-4fd7859e14f4> in <module>()
      1 #%matplotlib inline
----> 2 from opticspy.ray_tracing import *

~/anaconda3_501/lib/python3.6/site-packages/opticspy/ray_tracing/__init__.py in <module>()
----> 1 from . import lens, trace, glass_function, draw, analysis, field, codev

~/anaconda3_501/lib/python3.6/site-packages/opticspy/ray_tracing/codev.py in <module>()
----> 1 import lens
      2 '''
      3 CodeV seq file convertor
      4 return a Lens class
      5 '''

ModuleNotFoundError: No module named 'lens'
psychemedia commented 6 years ago

In Py2.7 I also get an error later on in the http://sterncat.github.io/files/Real_Ray_Tracing.html demo script:

New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True)

gives:

IOErrorTraceback (most recent call last)
<ipython-input-7-8b6207385061> in <module>()
      1 New_Lens.add_surface(number=1,radius=10000000,thickness=1000000,glass='air',output=True)
----> 2 New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True)
      3 New_Lens.add_surface(number=3,radius=-957.83146,thickness=9.349584,glass='air',output=True)
      4 New_Lens.add_surface(number=4,radius=-51.32104,thickness=2.032518,glass='N-SF2_schott',output=True)
      5 New_Lens.add_surface(number=5,radius=42.37768 ,thickness=5.995929 ,glass='air',output=True)

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/lens.pyc in add_surface(self, number, radius, thickness, glass, STO, output)
     80 #-----------------------surface functions-----------------------
     81         def add_surface(self,number,radius,thickness,glass,STO=False,output=False):
---> 82                 surface.add(self,number,radius,thickness,glass,STO,output)
     83         # def update_surface(self,number,radius,thickness,index,STO):
     84         #       surface.update(self,number,radius,thickness,index,STO)

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in add(self, number, radius, thickness, glass, STO, output)
     47     New_Surface = Surface(wavelength_list = self.wavelength_list,number=number,\
     48                             radius=radius,thickness=thickness,glass=glass,STO=STO,\
---> 49                             __diameter__=0)
     50     self.surface_list.append(New_Surface)
     51 

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in __init__(self, wavelength_list, number, radius, thickness, glass, STO, __diameter__)
     15         self.radius = radius
     16         self.glass = glass
---> 17         self.indexlist = glass_funcs.glass2indexlist(wavelength_list,glass)
     18         self.thickness = thickness
     19         self.STO = STO

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_funcs.pyc in glass2indexlist(wavelength_list, glassname)
     25                 glass_catalog_name = glassname[n+1:]
     26                 glass_name = glassname[:n]
---> 27                 catalog = RefractiveIndex()
     28                 for w in wavelength_list:
     29                         mat = catalog.getMaterial('glass', glass_catalog_name, glass_name)

/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_function/refractiveIndex.pyc in __init__(self, databasePath)
     35         """
     36         self.referencePath = os.path.normpath(databasePath)
---> 37         f = open(os.path.join(self.referencePath, os.path.normpath("library.yml")), "r")
     38         # print(f)
     39         self.catalog = yaml.safe_load(f)

IOError: [Errno 2] No such file or directory: '/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_database/library.yml'
Sterncat commented 6 years ago

Check if the glass folder in the code and in your opticspy folder. Maybe need add manually.

2018-08-04 2:23 GMT-07:00 Tony Hirst notifications@github.com:

In Py2.7 I also get an error later on in the http://sterncat.github.io/ files/Real_Ray_Tracing.html demo script:

New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True)

gives:

IOErrorTraceback (most recent call last)

in () 1 New_Lens.add_surface(number=1,radius=10000000,thickness=1000000,glass='air',output=True) ----> 2 New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True) 3 New_Lens.add_surface(number=3,radius=-957.83146,thickness=9.349584,glass='air',output=True) 4 New_Lens.add_surface(number=4,radius=-51.32104,thickness=2.032518,glass='N-SF2_schott',output=True) 5 New_Lens.add_surface(number=5,radius=42.37768 ,thickness=5.995929 ,glass='air',output=True) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/lens.pyc in add_surface(self, number, radius, thickness, glass, STO, output) 80 #-----------------------surface functions----------------------- 81 def add_surface(self,number,radius,thickness,glass,STO=False,output=False): ---> 82 surface.add(self,number,radius,thickness,glass,STO,output) 83 # def update_surface(self,number,radius,thickness,index,STO): 84 # surface.update(self,number,radius,thickness,index,STO) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in add(self, number, radius, thickness, glass, STO, output) 47 New_Surface = Surface(wavelength_list = self.wavelength_list,number=number,\ 48 radius=radius,thickness=thickness,glass=glass,STO=STO,\ ---> 49 __diameter__=0) 50 self.surface_list.append(New_Surface) 51 /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in __init__(self, wavelength_list, number, radius, thickness, glass, STO, __diameter__) 15 self.radius = radius 16 self.glass = glass ---> 17 self.indexlist = glass_funcs.glass2indexlist(wavelength_list,glass) 18 self.thickness = thickness 19 self.STO = STO /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_funcs.pyc in glass2indexlist(wavelength_list, glassname) 25 glass_catalog_name = glassname[n+1:] 26 glass_name = glassname[:n] ---> 27 catalog = RefractiveIndex() 28 for w in wavelength_list: 29 mat = catalog.getMaterial('glass', glass_catalog_name, glass_name) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_function/refractiveIndex.pyc in __init__(self, databasePath) 35 """ 36 self.referencePath = os.path.normpath(databasePath) ---> 37 f = open(os.path.join(self.referencePath, os.path.normpath("library.yml")), "r") 38 # print(f) 39 self.catalog = yaml.safe_load(f) IOError: [Errno 2] No such file or directory: '/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_database/library.yml' — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .
psychemedia commented 6 years ago

Ah, it's not copied into the py package folder.

Looking at https://github.com/Sterncat/opticspy/blob/master/setup.py there was some history of installing the package explicitly? Whatever the case, it doesn't seem to be being installed in my Py2.7 environment.

Should the files be installed as - and referenced as - data files? https://docs.python.org/2.7/distutils/setupscript.html#installing-additional-files (I'm not v. familiar with python package setup scripts...)

Sterncat commented 6 years ago

I think just download it from github and drag it into the folder. I will try to check it later. Thank you for finding this!

2018-08-09 17:04 GMT-07:00 Tony Hirst notifications@github.com:

Ah, it's not copied into the py package folder.

Looking at https://github.com/Sterncat/opticspy/blob/master/setup.py there was some history of installing the package explicitly? Whatever the case, it doesn't seem to be being installed in my Py2.7 environment.

Should the files be installed as - and referenced as - data files? https://docs.python.org/2.7/distutils/setupscript.html# installing-additional-files (I'm not v. familiar with python package setup scripts...)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Sterncat/opticspy/issues/25#issuecomment-411935248, or mute the thread https://github.com/notifications/unsubscribe-auth/ACiIha67WAcZvnUk1uZg6K8oP6al8H7rks5uPM4QgaJpZM4Vr9WG .