Python Module not found on upgrade

Hi everyone,

im trying to upgrade our python module from R21(Python27) to the most recent cinema version 2023.1.0. BuildNumber (CL387487.470010)

I followed the instructions on the website, https://developers.maxon.net/docs/Cinema4DPythonSDK/html/manuals/misc/python3_migration.html

I copied the library-module to the following paths:

c:\Users\tov\AppData\Roaming\Maxon\Maxon Cinema 4D 2023_BCDB4759_x\python39\libs\

C:\Users\tov\AppData\Roaming\Maxon\Maxon Cinema 4D 2023_BCDB4759\python39\libs

C:\Users\tov\AppData\Roaming\Maxon\python\python39\libs

The library components are not found with the error message:

Traceback (most recent call last):
  File "C:\Program Files\Maxon Cinema 4D 2023\plugins\vuframe-aura-commandline.pyp", line 31, in <module>
    import VC4D.Recipe as Recipe
  File "C:\Users\tov\AppData\Roaming\Maxon\Maxon Cinema 4D 2023_BCDB4759_x\python39\libs\VC4D\Recipe.py", line 11, in <module>
    from Tools import LogWithTimestamp
ModuleNotFoundError: No module named 'Tools'

The base plugin which uses the librarys resides in

C:\Program Files\Maxon Cinema 4D 2023\plugins

My module contains the usual suspects required:

__init__.py
__main__.py
_version.py

What did i miss?
Is it required to add a special Path to the systemvariables?

So, to answer my own question, seems that importing module components without module qualifiers does no longer work in 3.9?

from Tools import LogWithTimestamp is wrong

from VC4D.Tools import LogWithTimestamp is the correct way to go

Hey @fss,

Thank you for reaching out to us. Python 3 dropped support for implicit relative imports as they can be ambiguous im complex packages.

Python 3 makes a distinction between relative and absolute imports, dropping support for implicit relative imports. In Python 2.5+, use from future import absolute_import to get the same behavior as Python 3. To support older versions as well, only use absolute imports. Replace a relative import:

from xyz import abc

with an absolute import:

from mypackage.xyz import abc

Another way to deal with this would be to fix your __init__.py's. So, when you want everything in the module/package Tools to be also contained in the package VC4D, you must edit the __init__.py of VC4D

from .Tools import *

or more selective

from .Tools import LogWithTimestamp, ...

Cheers,
Ferdinand

Thanks alot Ferdinand.

I investigated some further and added the classes to the plugins list:

_plugins = [
    "Tools",
    "Recipe",

The error was also caused, by the executables having different libraries. Meaning, we call once cinema 4d.exe, which uses the {prefs}/python39/libs folder.

The second part of the plugin is executed using the classic Commandline.exe and uses the {prefs}_x/python39/libs folder.

Im a idiot, but a stubborn one.
Have a great day.

Topic can be locked now.