modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
22.92k stars 2.58k forks source link

mypackage/mymodule.mojo:1:1: error: unable to locate module 'mymodule' #823

Open fresh88888888 opened 1 year ago

fresh88888888 commented 1 year ago

Issue description

main.mojo

from mypackage import MyPair fn main(): let mine = MyPair(2, 4) mine.dump()

init.mojo

from .mymodule import MyPair

mymodule.mojo

struct MyPair: var first: Int var second: Int

fn __init__(inout self, first: Int, second: Int):
    self.first = first
    self.second = second

fn dump(self):
    print(self.first, self.second)

~/mojo/demo$ mojo build main.mojo

Included from mypackage/init.mojo:1: mypackage/mymodule.mojo:1:1: error: unable to locate module 'mymodule'

Steps to reproduce

struct MyPair: ^ @"$mymodule"::@MyPair mojo: /__w/modular/modular/KGEN/lib/MojoParser/DeclResolver.h:160: M::KGEN::LIT::ASTDecl &M::KGEN::LIT::DeclResolver::getDeclForTypeSymbol(mlir::SymbolRefAttr) const: Assertion `it != declForTypeSymbol.end() && "Unknown decl symbol!"' failed. [2763460:2763460:20230917,145124.125802:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [2763460:2763460:20230917,145124.125897:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes. Stack dump:

  1. Program arguments: mojo build main.mojo
  2. Crash resolving decl body at loc("main.mojo":6:1)

    fn main(): ^......... let mine = MyPair(2, 4) ...........................<

  3. Crash parsing statement at loc("main.mojo":7:5)
    let mine = MyPair(2, 4)

    ^......................< Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it): 0 mojo 0x000055df630e0f17 1 mojo 0x000055df630deaee 2 mojo 0x000055df630e15ef 3 libpthread.so.0 0x00007f9c580b5420 4 libc.so.6 0x00007f9c57b3e00b gsignal + 203 5 libc.so.6 0x00007f9c57b1d859 abort + 299 6 libc.so.6 0x00007f9c57b1d729 7 libc.so.6 0x00007f9c57b2efd6 8 mojo 0x000055df634ab83d 9 mojo 0x000055df634ab686 10 mojo 0x000055df634ab9d7 11 mojo 0x000055df634aba96 12 mojo 0x000055df6351b77b 13 mojo 0x000055df63513344 14 mojo 0x000055df635131ef 15 mojo 0x000055df634bc884 16 mojo 0x000055df634b4c8e 17 mojo 0x000055df634b30b8 18 mojo 0x000055df635093a9 19 mojo 0x000055df63509d2b 20 mojo 0x000055df6309093f 21 mojo 0x000055df630928b0 22 mojo 0x000055df6308d03f 23 mojo 0x000055df6308b926 24 libc.so.6 0x00007f9c57b1f083 __libc_start_main + 243 25 mojo 0x000055df6308b12e Aborted (core dumped)

AlmirNeeto99 commented 1 year ago

How is your directory structure?

hayahahaha commented 12 months ago

Same issue in here. I follow to docs and got issue struct MyPair: ^ @"$mymodule"::@MyPair mojo: /__w/modular/modular/KGEN/include/KGEN/MojoParser/DeclResolver.h:164: M::KGEN::LIT::ASTDecl &M::KGEN::LIT::DeclResolver::getDeclForTypeSymbol(mlir::SymbolRefAttr) const: Assertion `it != declForTypeSymbol.end() && "Unknown decl symbol!"' failed. Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes. Stack dump:

  1. Program arguments: mojo main.mojo
  2. Crash resolving decl body at loc("/home/haya/dev/mojo/main.mojo":4:1)

    fn main(): ^......... let mine = MyPair(2, 4) ...........................<

  3. Crash parsing statement at loc("/home/haya/dev/mojo/main.mojo":5:5)
    let mine = MyPair(2, 4)

    ^......................< Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it): 0 mojo 0x000055f27448c797 1 mojo 0x000055f27448a36e 2 mojo 0x000055f27448ce6f 3 libc.so.6 0x00007fcf23442520 4 libc.so.6 0x00007fcf23496a7c pthread_kill + 300 5 libc.so.6 0x00007fcf23442476 raise + 22 6 libc.so.6 0x00007fcf234287f3 abort + 211 7 libc.so.6 0x00007fcf2342871b 8 libc.so.6 0x00007fcf23439e96 9 mojo 0x000055f27486e59d 10 mojo 0x000055f27486e408 11 mojo 0x000055f27486e72a 12 mojo 0x000055f2748a2f34 13 mojo 0x000055f2748a3abe 14 mojo 0x000055f2748f103d 15 mojo 0x000055f2748b8c9b 16 mojo 0x000055f2748dcd6e 17 mojo 0x000055f2748d4a94 18 mojo 0x000055f2748d4946 19 mojo 0x000055f27488e952 20 mojo 0x000055f27488696e 21 mojo 0x000055f274884ea9 22 mojo 0x000055f274850d3a 23 mojo 0x000055f2748516ab 24 mojo 0x000055f274456d3f 25 mojo 0x000055f274441f60 26 mojo 0x000055f274455c4d 27 mojo 0x000055f27443bb6d 28 libc.so.6 0x00007fcf23429d90 29 libc.so.6 0x00007fcf23429e40 __libc_start_main + 128 30 mojo 0x000055f27443b0fe [1] 18349 IOT instruction (core dumped) mojo main.mojo

image

OS: Ubuntu 22.04

scottamain commented 11 months ago

@fresh88888888 I believe the problem is your filename. The "init" file needs to be surrounded by double-underscores: __init__.mojo, but your output indicates you did not do that:

~/mojo/demo$ mojo build main.mojo

Included from mypackage/init.mojo:1:
mypackage/mymodule.mojo:1:1: error: unable to locate module 'mymodule'

If you're folllowing the documentation here, then your file structure should look like this:

main.mojo
mypackage
├── __init__.mojo
└── mymodule.mojo

Please verify, thanks.

JulioBarros commented 11 months ago

I'm having the same issue on a M2 Ultra and today's install. My init file does have the double underscores.