Solved 3rd party APIs into pyp/pypv file

Hello PluginCafe! :)

Is it possible to use 3rd part APIs, e.g. Google Drive API, inside C4D's python plugin?

There is a pip install code on Google Developers webpage:
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Can I simply install it directly inside pyp file or import it by utilizing Niklas' code?

Hi @merkvilson first of all pip and Niklas localimport module is completely two different things.

  • pip is a python module manager (similar to package manager in unix). This means once it's installed to a python binary, it will be able to manage other modules, download them, install them with all their dependencies and update them and so on.
  • localimport is a python module that let you manage import in a local way while in Cinema 4D by default is global. For more information please read how the import function works in python.
    Meaning if you add a module named xyz to the sys.path from your plugin A and from plugin B you try to import another module named xyz, it will load the one from plugin A (the first one register).

Now how to install pip?

  2. Downloads the c4dpy version matching your Cinema 4D version. (Already included in R21)
  3. Moves c4dpy and in the Cinema 4D folder.
  4. Opens a shell to the Cinema 4D folder:
    • Window: Type cmd in the top path and press Enter.
    • Mac: Open a new shell, then with cd navigate to your Cinema 4D folder. (You can drag and drop the path).
  5. Runs this command line c4dpy This will execute the get-pip script which will, download and install the pip module.
  6. Now you can start to play with pip c4dpy -m pip install numpy. c4dpy allow to runs any module with the -m argument see c4dpy commandline. in this case I asked to pip to download and install numpy but any other 3rd party compatible with pip can be downloaded and used.

With that's said we do not provide support for 3rd party modules, so if it does not work with Cinema 4D Python environment, we can't help you.


thanks for the answer Maxim from Maxon

I was following this url from Niklas, but I guessed it was a bit old :-)

Also it is important to add to the env path this directory :
C:\Program Files\MAXON\Cinema 4D R20\resource\modules\python\libs\win64\python27.vs2008.framework\Scripts
which is the place where the have installed the new exec.

It has perfectly installed numpy-1.16.2

Question : do we need absolutely c4dpy.exe ? (as I managed to run during my previous test with the python.exe)

No you don't necessary need c4dpy, it's just more convenient and easy to find for everyone and for all future releases.

@m_adam Just a little addition on macOS you need to put: c4dpy/Contents/MacOS/c4dpy into the terminal, to link to the real executable. the simple c4dpy gives command not found.


this doesn't seem to work anymore.

./ -m pip install numpy                                                                                                              
Collecting numpy
  Downloading (7.3 MB)
(null)     |████████████████████████████████| 7.3 MB 5.3 MB/s (null)
(null)  Installing build dependencies ... (null)error
  ERROR: Command errored out with exit status 2:
   command: '/Applications/Maxon Cinema 4D R23/./' '/Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip' install --ignore-installed --no-user --prefix /private/tmp/pip-build-env-7f2h5t11/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i -- 'setuptools<49.2.0' 'wheel<=0.35.1' 'Cython>=0.29.21,<3.0'
       cwd: None
  Complete output (1 lines):
  /Applications/Maxon Cinema 4D R23/./ can't open file 'pip': is a directory (file:///Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip)
ERROR: Command errored out with exit status 2: '/Applications/Maxon Cinema 4D R23/./' '/Applications/Maxon Cinema 4D R23/resource/modules/python/libs/python37.macos.framework/lib/python3.7/site-packages/pip' install --ignore-installed --no-user --prefix /private/tmp/pip-build-env-7f2h5t11/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i -- 'setuptools<49.2.0' 'wheel<=0.35.1' 'Cython>=0.29.21,<3.0' Check the logs for full command output.
[1]    48826 segmentation fault  sudo ./ -m pip install numpy