mccdaq / mcculw

MCC Universal Library Python API for Windows
MIT License
78 stars 30 forks source link

Problem with ulw in Python no module named examples.console #14

Closed radiladrillingvibe closed 2 years ago

radiladrillingvibe commented 5 years ago

Nub here. I downloaded 2.7 Python and Instacal and we install the MCC UL Python API for Windows (mcculw) and did the upgrade. We got the script "a_in_scan_file.py" and ran it and we keep getting "ImportError: No module named examples.console"

I asked someone familiar with MCC and he told me to add "mcculw" to line 11.

We did it and it still wont run. We only need to write to a file on the machine.

Can you help so we can start the python code?

a_in_scan_file_pyNOTE.txt

kevin-j-morse commented 5 years ago

Hi @radiladrillingvibe

I am not sure why this project is structured the way it is but with Python 3. I found I had to add the following two lines to a_out_scan.py in order to be able to run it.

import sys

sys.path.append(r"C:\Users\Kevin\Documents\Python")

For me, the examples folder is inside of the the Python folder.

I could then run python.exe .\examples\console\a_out_scan.py from within the Python folder.

blakeNaccarato commented 4 years ago

~~My unofficial fork puts the examples back into the main package. So instead of configuring your IDE as outlined in the readme, you can do pip install git+https://github.com/blakeNaccarato/mcculw.git#egg=mcculw in a Python virtualenv (or put it in your requirements.txt).~~

I think my "fix" is overly-complicated, compared to the suggestion by @kevin-j-morse in https://github.com/mccdaq/mcculw/issues/14#issuecomment-513367978 above. At first I tried structuring the fork so that examples would install as a base-level package. Then I put examples back in mcculw, but this would require changing all imports from import examples... to import mcculw.examples.... Ultimately, just manually downloading examples.zip, extracting them, and appending the resulting directory to path as seen above is the way to go.

john518 commented 4 years ago

Since this issue is still open, may I suggest a slight variation to https://github.com/mccdaq/mcculw/issues/14#issuecomment-513367978

import os
import sys
source_dir = os.path.abspath(os.path.dirname(__file__))
home_dir = os.path.abspath(os.path.join(source_dir, os.pardir, os.pardir))
sys.path.append(home_dir)