(Python) Help making Pip work in Cinema 4D
-
Hi!,
As I was trying to find out a solution on how to do this in this forum, I came across this reply on how to install pip in Cinema 4D:
Now how to install pip? 1. Downloads https://bootstrap.pypa.io/get-pip.py. 2. Downloads the c4dpy version matching your Cinema 4D version. (Already included in R21) 3. Moves c4dpy and get-pip.py 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 get-pip.py. 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. Cheers, Maxime.
I got some questions:
- for step 1, when I opened the link, it redirects me to a wall of code. Do I copy + paste it in Python's IDLE and make a .py out of it? how do I install it exactly
- for step 2, I am confused which one I should download here
- for step 3, by "Cinema 4D folder" which one do you mean? like the exact path?
- for step 4, I do something like this right?
(I select "Open PowerShell window here" then run the code from step 5, right?)
I want to use pip to make this line of code work inside Cinema 4D:
from pynput.keyboard import Key, Controller import time keyboard = Controller() time.sleep(2) keyboard.press('4') keyboard.release('4')
Will this code work when I successfully follow the "how to install pip" instruction?
Thank you guys -
Hi,
-
It is a Python script - the installation routine for
pip
. You have to run it with a Python interpreter, or more preciselyc4dpy
in this case. -
c4dpy
is not listed there anymore, because it is included with the standard Cinema installation since R21. So if you are on R21+ you can skip this step. -
See 2.
-
Yes, that is one possible way. It does not matter if you use the PowerShell or the standard shell (i.e. cmd.exe). You can also just paste the script into Cinema's script manager and execute it from there.
-
While you can get
pip
running onc4dpy
, it is very much not a vanilla CPython interpreter, butpip
operates under the assumption that it is. Which can lead to all sorts of problems - which in turn can corrupt package installations.
The other problem is that these keyboard input libraries are often itself a bit dicey and Cinema is certainly not an easy application to send key strokes to. There is also the problem that Cinema's Python code runs in a synchronised environment dictated by the app, which in turn can interfere with keyboard OS API calls of
pynput
.Or in short: You will have to try for yourself. But on the other hand I am certain there is an easier solution for your problem. Be it a native
c4dpy
solution or one, where you usec4dpy
just as a glue language.Cheers,
zipit -
-
Hi @Fowdy , thanks for reaching out to us.
I prefer to answer inline to your points:
when I opened the link, it redirects me to a wall of code. Do I copy + paste it in Python's IDLE and make a .py out of it? how do I install it exactly
You can save the page straight from the browser as a .py file (let's say you save it on the Desktop)
I am confused which one I should download here
No need to download anything: Cinema 4D R23 already ships with the c4dpy executable (c4dpy.exe
by "Cinema 4D folder" which one do you mean? like the exact path?
I do something like this right?Assuming that Cinema 4D has been installed in the default path proposed by the installer in
C:\Program Files\Maxon Cinema 4D R23
just open you the Command Line (not PowerShell) and type:
C:\> "C:\Program Files\Maxon Cinema 4D R23\c4dpy.exe" %USERPROFILE%\Desktop\get-pip.py
Upon the pip installation ends gracefully, you can install your pynput module typing
C:\> "C:\Program Files\Maxon Cinema 4D R23\c4dpy.exe" -m pip install pynput
Finally with regard to the question about the code, I can't judge since we don't support or advice external python modules, but by a brief look I doubt that code will work in a script. It could be much better if you could better explain your final goal and see if it can be achieved with native C4D API toolset.
Best, Riccardo
-
Hi,
without further feedback, we will consider this thread as solved by Wednesday and flag it accordingly.
Cheers,
Ferdinand