PYTHONPATH not appended to sys.path in Cinema 4D 24
-
Hello,
We've been using Cinema 4D R20 and R21 for some years and now we're preparing to migrate to the S24.
During these years, we've developed some Python Packages that are imported by our Python plugins.
In C4D 20 and 21 these modules have always been imported by the plugin with no errors.
In C4D 24, however, the same operation raises a "ModuleNotFoundError: No module named ..."
The paths to our packages are appended to PYTHONPATH environment variable before launching C4D.
Once C4D is launched, I've checked the PYTHONPATH in the Extension > Console > Python and the packages' paths are all there.
The sys.path however doesn't contain the Packages Path, as if the $PYTHONPATH were not inserted into the sys.path upon launching C4D.
Do you know if this is a known issue and if there's a "workaround" for importing external python packages in our C4D plugins (any workaround besides looping through the PYTHONPATH paths and appending them to the sys.path)?
These tests were executed from Cinema S24.111 on Windows 10 Enterprise.
Thanks for your help,
Rodrigo
Ps.: This issue seems to be related to the issue described in https://developers.maxon.net/forum/topic/11143/content-of-pythonpath-not-appended-to-sys-path. However, as the latter is focused on other versions of C4D and as it was marked as "solved", I've preferred to create a new topic. -
Hello @rodrigo,
Thank you for reaching out to us. With S24 you must setup an environment variable called
C4DPYTHONPATH39
to achieve an effect similar toPYTHONPATH
:S24 will then be able to import modules and packages from that path.
Cheers,
Ferdinand -
Ok, I didn't know we could/should set this environment variable in C4D 24.
Thanks Ferdinand for your help!
Cheers,
Rodrigo -
Hello, how do you use C4DPYTHONPATH environnement variable with C4D R21?
C4DPYTHONPATH is not appended to sys.path
I created it in windows environement variables, and then i launch C4D R21, when i type "import moduleX" the module could not be imported...
Cheers
-
Hello @f2b,
Thank you for reaching out to us. In R21, you must use
PYTHONPATH
. This all is dependent on the CPython version your Cinema 4D is using. When this topic came up, I took the occasion to update our Python documentation on Python Libraries. There you will find information on the multiple approaches one can use to include Python libraries with one or multiple Cinema 4D installations.The caveat is, however, that
R21
is technically out of scope of SDK support and thereforePYTHONPATH
is not included on that page, but I will fix that. For me this works without issues:
The slight problem with the R21 module search path
PYTHONPATH
is that it is shared with the standardCPython
interpreter when you happen to have one on your machine.Cheers,
Ferdinand -
Excellent! Thanks you a lot
Regards,