Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    ModuleNotFoundError, but the file is in the same folder

    Cinema 4D SDK
    windows python s26
    2
    3
    510
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Gaal Dornik
      last edited by ferdinand

      Hello, i created a python file named test.py in the Script Manager and trying to import it in a new python script, but i'm getting ModuleNotFoundError. What's wrong? - Both files are in the same location.

      import test
      
      Traceback (most recent call last):
        File "C:\Users\Sun\AppData\Roaming\MAXON\Cinema 4D R26_8BE0107C\library\scripts\untitled.py", line 3, in <module>
          import test
      ModuleNotFoundError: No module named 'test'
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Gaal Dornik
        last edited by ferdinand

        Hello @Gaal-Dornik,

        Thank you for reaching out to us. Please include the version number you are developing for in the future as a tag in your questions.

        This is happening because the script folders (and also plugin folders) are not on the module search path of the Python instance of Cinema 4D. When you run a vanilla CPython interpreter, the path where your script lies is set as the working directory; and the working directory is injected into the module search paths. In Cinema/c4dpy, the working directory is the application path.

        In S26 and higher, you can either place shared components in one of the library folders or modify the search paths, both have been documented in the Python Libraries Manual. In 2024 you can also use mxutils.LocalImportPath which has been added for the exact scenario you are in.

        import mxutils
        
        with LocalImportPath(__file__):
            import test
        

        LocalImportPath does more or less exactly what I described in the Python Libraries Manual under Local Plugin Search Paths.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • G
          Gaal Dornik
          last edited by Gaal Dornik

          I see, thanks. But honestly i don't get it why the plugins folder isn't in the search path...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post