Ren'Py VS-Code: Python Install & Load Module?

dusty stu

Well-Known Member
Jan 24, 2018
1,735
1,557
I must be a dumbass because I can't import new modules

Using VS-Code
Python 3.10
(not using a virtual environment atm)
Making code for renpy game.


Code:
import cv2
from supportfiles.pymediainfo import MediaInfo
gives
You don't have permission to view the spoiler content. Log in or register now.

I tried
Code:
pip install pymediainfo 
pip install opencv-python
in the console, and the console said they installed correctly. But the compiler still can't find them (see above error).

TLDR How do you install modules into the project?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
TLDR How do you install modules into the project?
Well, it's said in Ren'Py documentation, :
Ren'Py can import pure-Python modules and packages. First-party modules and packages – ones written for the game – can be placed directly into the game directory. Third party packages can be placed into the game/python-packages directory.
People will not play on your computer, and they'll also not install Python and the right package(s) just to play your game. Therefore you've to put the package in a place where the game can access them, and that will be included in the distribution archive.


This being said, I wonder why you want to use OpenCV with Ren'Py.
While not perfect, Ren'Py already come with a lot of image manipulation features ( , the , the , the and its shaders, and the , without counting the access to PyGame that let you draw in real time). Of course, all this is not as advanced that what is possible with a library like OpenCV, but it's also a question of ratio time/interest. A game need to stay playable on 10 years old slow computer with not much RAM, and without slowdowns every now and then because the image need to much time to be proceeded.
 

dusty stu

Well-Known Member
Jan 24, 2018
1,735
1,557
Well, it's said in Ren'Py documentation, :


People will not play on your computer, and they'll also not install Python and the right package(s) just to play your game. Therefore you've to put the package in a place where the game can access them, and that will be included in the distribution archive.


This being said, I wonder why you want to use OpenCV with Ren'Py.
While not perfect, Ren'Py already come with a lot of image manipulation features ( , the , the , the and its shaders, and the , without counting the access to PyGame that let you draw in real time). Of course, all this is not as advanced that what is possible with a library like OpenCV, but it's also a question of ratio time/interest. A game need to stay playable on 10 years old slow computer with not much RAM, and without slowdowns every now and then because the image need to much time to be proceeded.
I am very green with renpy. I mostly code c# for my dayjob, and occasionally python in spare time.

Thank you for the tips. Really appreciate it.
 

dusty stu

Well-Known Member
Jan 24, 2018
1,735
1,557
Well, it's said in Ren'Py documentation, :


People will not play on your computer, and they'll also not install Python and the right package(s) just to play your game. Therefore you've to put the package in a place where the game can access them, and that will be included in the distribution archive.


This being said, I wonder why you want to use OpenCV with Ren'Py.
While not perfect, Ren'Py already come with a lot of image manipulation features ( , the , the , the and its shaders, and the , without counting the access to PyGame that let you draw in real time). Of course, all this is not as advanced that what is possible with a library like OpenCV, but it's also a question of ratio time/interest. A game need to stay playable on 10 years old slow computer with not much RAM, and without slowdowns every now and then because the image need to much time to be proceeded.
I'm trying to write a module that will auto-downsize too-big videos.

# method 1: get the dimensions with cv2
Code:
    python:
        import sys
        sys.path.append('/usr/local/lib/python3.10/site-packages')
        completePath = clip1
        import cv2
        vid = cv2.VideoCapture(completePath)
        hh = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
        ww = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
# method 2: get the dimensions with MediaInfo
Code:
    $ dim_x = 1920
    $ dim_y = 1080

    python:
        from pymediainfo import MediaInfo
        media_info = MediaInfo.parse(completePath)
        for track in media_info.tracks:
            if track.track_type == 'Video':
          
                dim_x = track.width * 1.0   # multiply 1.0 to ensure float
                dim_y = track.height * 1.0
# do the resize
Code:
    if dim_x > dim_y:

        $ scale = 1920 / dim_x
        $ dim_y = scale * dim_y
    
        $ renpy.movie_start_displayable(size=(1920,dim_y), play=completePath, loops=-1)

    else:

        $ scale = 1080 / dim_y
        $ dim_x = scale * dim_x

        $ renpy.movie_start_displayable(size=(dim_x,1080), play=completePath, loops=-1)
 
Last edited:

dusty stu

Well-Known Member
Jan 24, 2018
1,735
1,557
image manipulation features
I'm working with .webm videos. Not sure if those libraries apply here.

People will not play on your computer, and they'll also not install Python and the right package(s) just to play your game. Therefore you've to put the package in a place where the game can access them, and that will be included in the distribution archive.
So where would I drop the the packages? At the root were the renpy exe is, or on the same level as the renpy script?
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
I'm trying to write a module that will auto-downsize too-big videos.
Why do you need a module for that ?

If it's to resize the movie before you release the game, there's tools way more adapted for this.
If it's to resize the movie in real time, you shouldn't, they should have the right size beforehand.
If you really need to resize the movies in real time, Ren'Py already know how to do this:
Python:
image myMovie = Movie(play="PATH/TO/MOVIE/movie.webm" )

label whatever:
    show myMovie:
        zoom 0.5   # Will resize the movie at 50%
Or even, if the resizing should be constant:
Python:
image myMovie:
    Movie(play="PATH/TO/MOVIE/movie.webm" )
    zoom 0.5  # Still resizing at 50%

So where would I drop the the packages? At the root were the renpy exe is, or on the same level as the renpy script?
It's wrote, explicitly, in my first answer.


Okay so I put the mediainfo folder into game/lib/python2.7/
and got this error:
You're trying to import a package for Python 3.10, in a script working with Python 2.7...
Even if the Python branches 2.x and 3.x were compatible, what they aren't, there would be tons of reason for this to not be a good idea.
 

dusty stu

Well-Known Member
Jan 24, 2018
1,735
1,557
Why do you need a module for that ?

If it's to resize the movie before you release the game, there's tools way more adapted for this.
If it's to resize the movie in real time, you shouldn't, they should have the right size beforehand.
If you really need to resize the movies in real time, Ren'Py already know how to do this:
Python:
image myMovie = Movie(play="PATH/TO/MOVIE/movie.webm" )

label whatever:
    show myMovie:
        zoom 0.5   # Will resize the movie at 50%
Or even, if the resizing should be constant:
Python:
image myMovie:
    Movie(play="PATH/TO/MOVIE/movie.webm" )
    zoom 0.5  # Still resizing at 50%



It's wrote, explicitly, in my first answer.




You're trying to import a package for Python 3.10, in a script working with Python 2.7...
Even if the Python branches 2.x and 3.x were compatible, what they aren't, there would be tons of reason for this to not be a good idea.
Le sigh
I think ima bout to give up. python modules in renpy projects in vs-code are just too complex for me.
this would be super easy if this were c# or even just python.

The game I'm working on ranomly selects a 2-10 second video to play. From those videos, they all have differant resolutions and aspect-ratios. Resizing each individual video can take a lot of time, and be error prone since it's done manually. I want the code to do the down-sizing so I can just drop videos into the folder without having to double check the resolution of each one. There is somthing like 150 video clips so far and counting.

Not every video needs to re resized, so that's what the module is needed for; to get the -x and y-dimensions.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
I think ima bout to give up. python modules in renpy projects in vs-code are just too complex for me.
The soupir...

What is complex in: "First-party modules and packages – ones written for the game – can be placed directly into the game directory. Third party packages can be placed into the game/python-packages directory."
Edit: Oh, and obviously also in the fact that you can't run a module made for Python 3.10 while you use Python 2.7...


The game I'm working on ranomly selects a 2-10 second video to play. From those videos, they all have differant resolutions and aspect-ratios.
Therefore instead of using zoom, that would resize accordingly to the actual dimension, use size, that will force the dimension of the video:
Code:
image myMovie:
    Movie(play="PATH/TO/MOVIE/movie.webm" )
    size ( 100, 100 )
 
Last edited: