# Can I import a py with no class?

**URL:** <https://discourse.slicer.org/t/can-i-import-a-py-with-no-class/9468>\
**Category:** Development\
**Created:** [December 10, 2019, 11:36pm UTC](https://discourse.slicer.org/t/can-i-import-a-py-with-no-class/9468 "2019-12-10T23:36:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [December 10, 2019, 11:36pm UTC](https://discourse.slicer.org/t/can-i-import-a-py-with-no-class/9468/1 "2019-12-10T23:36:04Z")

</div>

I writed a py file which could run in my connda and I went implant it in slicer just litter modify.  
When I test it and some erro happen just like:  
RuntimeError: qSlicerScriptedLoadableModule::setPythonSource - Failed to load scripted loadable module: class off2obj was not found in file C:/Users/1/Desktop/3dp/off2obj.py…

So, firstly, can I import it with no class?

and secondly, can I run my py file in python interactor(slicer) directly just like run it in Anaconda Prompt?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 11, 2019, 1:45am UTC](https://discourse.slicer.org/t/can-i-import-a-py-with-no-class/9468/2 "2019-12-11T01:45:06Z")

</div>

If you want to run your script at every startup then you can put it into your .slicerrc.py file (Application settings / General / Application startup script).

If you want to run your script from the command-line then you can launch Slicer like this: `Slicer.exe --python-script /tmp/test.py`

However, the simplest and most flexible is to create a Python scripted module. You can then offer a GUI to use your script (not mandatory, but useful) and the function can be executed from Slicer’s Python console or from other modules.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 11, 2019, 3:11pm UTC](https://discourse.slicer.org/t/can-i-import-a-py-with-no-class/9468/3 "2019-12-11T15:11:00Z")

</div>

In python2 there was also `execfile('/tmp/code.py')` but it was removed for python3. Instead I tend to use this little recipe for quick tests: `eval(open('/tmp/code.py').read())`
