Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zty1122zty opened this issue Dec 23, 2023 · 5 comments
Open

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

zty1122zty opened this issue Dec 23, 2023 · 5 comments

Comments

@zty1122zty
Copy link

尝试了以下方法均识别不到模块:
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
Copy link

Set PYTHONPATH:

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

@zty1122zty
Copy link
Author

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

@Lilneo786
Copy link

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
Copy link
Author

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

@Lilneo786
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants