• Civ7 is already available! Happy playing :).

Steam Ver: Failed initializing Python

Panda.Proxy

Chieftain
Joined
Dec 25, 2015
Messages
1
Hey everyone,

I am trying to run this mod with the Steam game version, but in middle of loading it errors out saying "Failed initializing Python". Other mods seem to be working fine, just this one doesn't. The mod is installed in default location in Documents\My Games.

Any advice?
 
Did you ever figure this out? I am having the same issue now.
 
Sadly it is a crashing error. Ya Idk, I give up at this point. I have tried reinstalling the game to different locations including defaults.

I have put the mod in multiple different directories.

I even uninstalled steam and put it in a different location.

I even tried old versions of the mod by installing svn.

I have completely removed all settings from the documents folder as well.

No matter what I do, other mods work fine, the base game loads fine, but this mod fails. I have the exact error I will post here once I get back in front of my computer.
 
Just out of curiosity: Can you install my mod seen in my signature? CoM is a modmod of Rom-AND2.
Your mod fails as well. Same error.

Code:
Traceback (most recent call last):

  File "CvAppInterface", line 65, in init

AttributeError: 'module' object has no attribute 'setdefaultencoding'
ERR: Python function init failed, module CvAppInterface
 
Your mod fails as well. Same error.
I was afraid it would.

Since AND2 developers are rarely around anymore (and I'm no programmer) I suggest you ask this question in Quick Modding Questions thread. It's not a modding question per se but it may turn out to need some modding and the experts are active in that thread. Good luck 🙂
 
I have tried reinstalling the game to different locations including defaults.
Have you tried making path short? Civ4 has a limitation on length, maybe including packaged files too. It's easy to run out for Steam.
And make sure there is NO folder in Documents\My Games\Beyond the Sword\MODS\ for the mod you test - this could screw up your experiments previously.
Are you on Windows?
 
Your mod fails as well. Same error.
Spoiler :
Code:
Traceback (most recent call last):

  File "CvAppInterface", line 65, in init

AttributeError: 'module' object has no attribute 'setdefaultencoding'
ERR: Python function init failed, module CvAppInterface
The offending line is the last one in this function:
Spoiler :
Code:
def init():
	# for PythonExtensions Help File
	PythonHelp = 0		# doesn't work on systems which haven't installed Python
			
	# dump Civ python module directory
	if PythonHelp:		
		import CvPythonExtensions
		helpFile=file("CvPythonExtensions.hlp.txt", "w")
		sys.stdout=helpFile
		import pydoc                  
		pydoc.help(CvPythonExtensions)
		helpFile.close()
	
	sys.stderr=CvUtil.RedirectError()
	sys.excepthook = CvUtil.myExceptHook
	sys.stdout=CvUtil.RedirectDebug()
	# ENABLE_UTF
	sys.setdefaultencoding('utf-8')
And that's the only RoM addition here; the start of the function is as in BtS. I get a lot of Google hits for setdefaultencoding (SDE for brevity) not being an attribute of sys; this StackOverflow answer seems to sum up the state of affairs well. So SDE has been removed entirely in Python 3. But I find it hard to imagine that somehow Civ launches a Python 3 interpreter (instead of 2.4) on your end. It sounds like just calling SDE as RoM does shouldn't work in Python 2 either, or maybe it just shouldn't be expected to work reliably. Adding reload(sys) right above the SDE line - and with the same indentation - might make it work reliably. The mod's version of CvAppInterface.py is in \Assets\Python\EntryPoints. Also worth a try: Just removing the SDE line (or commenting it out with a leading #). I'm guessing that it wasn't just added somehow pre-emptively - but to solve specific encoding problems. But maybe those problems won't even affect your system or they'll affect only some few unimportant bits of game text that'll get garbled. Or perhaps removing the line will immediately result in another critical error, hinting more clearly at an underlying problem.
 
Have you tried making path short? Civ4 has a limitation on length, maybe including packaged files too. It's easy to run out for Steam.
And make sure there is NO folder in Documents\My Games\Beyond the Sword\MODS\ for the mod you test - this could screw up your experiments previously.
Are you on Windows?
Mods folder is empty.

As a long term programmer, I always keep all my path names super short and normally never install to default locations.

Windows 11, which I am beginning to think is the issue here.

The offending line is the last one in this function:
Spoiler :
Code:
def init():
    # for PythonExtensions Help File
    PythonHelp = 0        # doesn't work on systems which haven't installed Python
           
    # dump Civ python module directory
    if PythonHelp:       
        import CvPythonExtensions
        helpFile=file("CvPythonExtensions.hlp.txt", "w")
        sys.stdout=helpFile
        import pydoc                 
        pydoc.help(CvPythonExtensions)
        helpFile.close()
   
    sys.stderr=CvUtil.RedirectError()
    sys.excepthook = CvUtil.myExceptHook
    sys.stdout=CvUtil.RedirectDebug()
    # ENABLE_UTF
    sys.setdefaultencoding('utf-8')
And that's the only RoM addition here; the start of the function is as in BtS. I get a lot of Google hits for setdefaultencoding (SDE for brevity) not being an attribute of sys; this StackOverflow answer seems to sum up the state of affairs well. So SDE has been removed entirely in Python 3. But I find it hard to imagine that somehow Civ launches a Python 3 interpreter (instead of 2.4) on your end. It sounds like just calling SDE as RoM does shouldn't work in Python 2 either, or maybe it just shouldn't be expected to work reliably. Adding reload(sys) right above the SDE line - and with the same indentation - might make it work reliably. The mod's version of CvAppInterface.py is in \Assets\Python\EntryPoints. Also worth a try: Just removing the SDE line (or commenting it out with a leading #). I'm guessing that it wasn't just added somehow pre-emptively - but to solve specific encoding problems. But maybe those problems won't even affect your system or they'll affect only some few unimportant bits of game text that'll get garbled. Or perhaps removing the line will immediately result in another critical error, hinting more clearly at an underlying problem.
This is what my research found as well, which is why my first question in the C2C discord was can civ4 use a different version of python. I was assured that it was impossible, but who knows.

I added that line into the file, but no change. Since it is python assuming it does not need to be compiled or anything.

Commenting out the line allows the game to load. Thanks for the tip.
 
Top Bottom