Maya 2022 & Python: __init__.pyc error?

Hi there,

I have a script written in python 2.7 and I have converted it for python 3.7 of maya 2022.
In the folder of my new version I have deleted all the pyc, then I launched the tool via maya 2022.
I have no error and a bunch of new pyc files are created. Excepted that I don’t have any new init.pyc .

However when I try to open my tool again with a folder that only contains the pyc(So I can share my tool with other people). Well, it’s like maya can’t find my package and import it (Despite being in the maya2022/script/ folder).

Am I missing something with the __init__pyc files ?

Furthermore when I tried with some old __ini__pyc I have an error raised about bad magic numbers … :confused:

Cheers,

Psichari

Just an absolute shot in the dark - I know starting with Python 3.x any .pyc files went into a pycache folder at the top of each module. Do you have such a folder?

Well a few months ago I did a test and I had a pycache folder.
But now when I launch my .py file there is no pycache folder :confused:

Also I notice that I have a bad magic numbers error with my regular pyc files of my package, not just the init.pyc

I’m trying to upgrade to Maya 2022.1 but even the autodesk downloader is buggy, I can’t start to unpack the update :robot:

No lie, one of the first things I do on any machine is disable generating pyc files because I hate them with a passion.
Either by using PYTHONDONTWRITEBYTECODE environment variable or sys.dont_write_bytecode = True

Well the thing is, I want to share pyc instead of my source .py files.
I think I have solve the init.pyc, now it’s generating the files.
However several people who get my files have an error :

Error: ImportError: file C:\Program Files\Autodesk\Maya2022\Python37\lib\site-packages\shiboken2\files.dir\shibokensupport__feature__.py line 142: bad magic number in ‘script’: b’\x03\xf3\r\n’

That’s strange because when I use the same pyc on my maya 2022.1, everything is running perfectly (To test the files I have a separated folder with only my pyc version and I tested on a newly booted version of maya 2022)

Bytecode can be easily decompiled, and is effectively equivalent to running the code through an obfuscator. You lose most variable names, and all the comments and docstrings. That’s all that happens either way. The structure still stays the same. So I’d suggest just running it through an obfuscator and calling it a day if this is really that important to you.

But unless you’re selling your code, please just distribute the source

Indeed the code is for a commercial plugin.

However I finally found the issue… I installed 3 plugin on my Maya 2022 : Ziva dynamics ,Quixel Bridge and Mgear.
One of those plugins installed an environnement variable to set my python version to 2.7.
So I thought I was coding in python 3X (and was expected the python 3x error to be catched up) but in fact I was coding and compiling for python 2X.

That’s why I guess everything was not working with my python 2X on my users maya python 3X :confused: