skywind3000 / PyStand

:rocket: Python Standalone Deploy Environment !!
MIT License
641 stars 75 forks source link

加密问题:始终识别不到模块 #69

Open zty1122zty opened 7 months ago

zty1122zty commented 7 months ago

尝试了以下方法均识别不到模块: 1.将script目录下的所有.py直接压缩并改为.egg放在.exe同级目录下 2.直接将script目录压缩为egg文件并放在exe同级 3.不压缩,将所有py文件替换为pyc文件 4.将所有py文件转化为pyd后放在script下 图片2 int文件配置如下:

#  vim: set ts=4 sw=4 tw=0 et ft=python :
import sys, os
from multiprocessing import freeze_support
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'.\site-packages\PyQt5\Qt5\plugins'
os.chdir(os.path.dirname(__file__))
sys.path.append(os.path.abspath('script'))
sys.path.append(os.path.abspath('script.egg'))
if __name__ == '__main__':
    if not hasattr(sys, 'frozen'):
        sys.frozen = True
    freeze_support()
    import main
    try:
        main.startwin()
    except Exception as e:
        import logging
        logging.basicConfig(filename='log/Pystand-log.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
        logging.error(e)

只有将py放在script目录下且无压缩才能识别到。

请问如何处理才能正确识别到pyd文件以满足加密?

Lilneo786 commented 7 months ago

Set PYTHONPATH:

import sys, os sys.path.append(os.path.abspath('path/to/directory/containing/pyd/files'))

zty1122zty commented 7 months ago

int文件中line 6已如此设置,pyd files的目录为script。

Lilneo786 commented 7 months ago

import sys, os from multiprocessing import freeze_support

Set the QT_QPA_PLATFORM_PLUGIN_PATH environment variable

os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'.\site-packages\PyQt5\Qt5\plugins'

Change the current working directory to the directory of this script

os.chdir(os.path.dirname(file))

Add the 'script' directory to sys.path

sys.path.append(os.path.abspath('script'))

Add the 'script.egg' directory to sys.path (this part is not typical)

sys.path.append(os.path.abspath('script.egg'))

if name == 'main':

Check if the script is running as a frozen executable

if not hasattr(sys, 'frozen'):
    sys.frozen = True

freeze_support()

# Import the 'main' module from the 'script' directory
import main

try:
    # Call the 'startwin' function from the 'main' module
    main.startwin()
except Exception as e:
    import logging
    logging.basicConfig(filename='log/Pystand-log.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
    logging.error(e)
zty1122zty commented 7 months ago

已如此设置,但是只能识别py文件,而不能识别pyc或pyd

Lilneo786 commented 7 months ago

import sys, os

Add the directory containing .pyc and .pyd files to sys.path

sys.path.append(os.path.abspath('script'))

Check File Extensions: Ensure that your .pyc and .pyd files have the correct file extensions and are compatible with the Python version you are using. .pyc files are compiled Python files, and .pyd files

Import Statements: In your code, make sure that you are using the correct import statements to load modules from the script directory. You should use the module name without the file extension when importing.

For example, if you have a file named mymodule.py in the script directory, you should import it like this: import mymodule

Permissions: Check read permissions for .pyc and .pyd files. Environment: Confirm sys.path changes are effective in your Python environment, especially when using tools like PyInstaller or cx_Freeze. Dependencies: Check for correct installation and accessibility of external libraries for .pyd files. Debugging: Add debugging statements to print sys.path values and verify file locations if issues continues.