How to import modules (on Windows)? [Solved]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
AJFLink
Newbie
Posts: 16
Joined: Mon Nov 05, 2018 2:04 am
Contact:

How to import modules (on Windows)? [Solved]

#1 Post by AJFLink »

On Mac, to add a custom/third-party module to your Ren'Py game, you only need to do the following (assuming a file called mymodule.py exists in the game directory):

Code: Select all

python:
	from sys import path
	
	path.append('/Users/username/Desktop/mygame/game')
	
	import mymodule
However, doing the same on Windows:

Code: Select all

python:
	from sys import path
	
	path.append('C:\\Users\\username\\Desktop\\mygame\\game')
	
	import mymodule
Always results in:
WindowsError: [Error 126] The specified module could not be found

Changing the current working directory via os.chdir does not work.

Strangely, having this code removed and manually typing the commands into Ren'Py's console allows this to work. I am clearly doing something wrong but I have no idea what. Is there a significant difference as to how the Windows version of Ren'Py handles modules compared to how Mac version of Ren'Py handles modules or am I simply overlooking something very simplistic?
Last edited by AJFLink on Thu Apr 23, 2020 10:10 am, edited 1 time in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to import modules (on Windows)?

#2 Post by Remix »

Why are you using an absolute path for imports... You will need to include the module files in your build anyway, so just put them inside ./game somewhere and relative path them

You can even add the folder (before using import) with
$ renpy.add_python_directory("subfolder/folder")

Ren'Py by default will add the (not existing) folder named "python-packages" so you could create a folder named exactly that (inside game/) and just import (presuming the module is just pure Python)
Frameworks & Scriptlets:

AJFLink
Newbie
Posts: 16
Joined: Mon Nov 05, 2018 2:04 am
Contact:

Re: How to import modules (on Windows)?

#3 Post by AJFLink »

Thanks! That really helped out!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot]