dhopp1 / nowcast_lstm

LSTM neural networks for nowcasting economic data.
MIT License
59 stars 10 forks source link

ModuleNotFoundError: No module named 'nowcast_lstm.LSTM'; 'nowcast_lstm' is not a package #3

Closed ahbon123 closed 1 year ago

ahbon123 commented 1 year ago

Hello, when I use the following command to import a package:

from nowcast_lstm.LSTM import LSTM

the following error message appears:

ModuleNotFoundError: No module named 'nowcast_lstm.LSTM'; 'nowcast_lstm' is not a package

How to solve it? Thanks a lot.

dhopp1 commented 1 year ago

Hello, this looks like you don't have the library installed, did you install it with pip install nowcast-lstm?

ahbon123 commented 1 year ago

Yes, I installed the package, but it raised an error as well: ModuleNotFoundError: No module named 'nowcast_lstm.LSTM'; 'nowcast_lstm' is not a package.

dhopp1 commented 1 year ago

I would need more information to be able to help you further (operating system, environment, IDE, are you using Anaconda or not, etc.). The issue seems to be with installing it and getting it recognized in your path, which is a more general Python/environment issue and not necessarily specific to the library.

ahbon123 commented 1 year ago

Sorry for the late reply. My computer system is macOS, and the Python IDE I use is Pycharm. As shown in the picture below, I installed your library, but when running the script, the following error will appear. I'm not quite sure what caused it.

image

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-9a208c1df7a5>", line 1, in <cell line: 1>
    runfile('/Users/x/Documents/ss/utils/nowcast_lstm.py', wdir='/Users/x/Documents/ss/utils')
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/x/Documents/ss/utils/nowcast_lstm.py", line 1, in <module>
    from nowcast_lstm.LSTM import LSTM
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/x/Documents/ss/utils/nowcast_lstm.py", line 1, in <module>
    from nowcast_lstm.LSTM import LSTM
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'nowcast_lstm.LSTM'; 'nowcast_lstm' is not a package
dhopp1 commented 1 year ago

If everything is installed correctly, one simple possibility is that you've named your file the same thing as the library, i.e., "nowcast_lstm.py" from where you're trying to import it. If this is the case, that error will show even if the library is installed. Try just running python from the terminal and importing the libray and see if it works then.

ahbon123 commented 1 year ago

Sorry, my mistake, it was truly a file name issue. I had a file named nowcast_lstm.py.