Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyinstaller在创建exe文件时无法导入pylsd_Python_Python 3.x_Ctypes_Pyinstaller - Fatal编程技术网

Python Pyinstaller在创建exe文件时无法导入pylsd

Python Pyinstaller在创建exe文件时无法导入pylsd,python,python-3.x,ctypes,pyinstaller,Python,Python 3.x,Ctypes,Pyinstaller,我正在尝试为一个程序创建exe文件,我使用了 pyinstaller --onefile filename.py 创建exe文件 我的代码使用pylsd,但pyinstaller无法导入包。 当我尝试运行exe文件时,它显示: Traceback (most recent call last): File "final_lines.py", line 4, in <module> from pylsd.lsd import lsd File "c:\users\ya

我正在尝试为一个程序创建exe文件,我使用了

    pyinstaller --onefile filename.py 
创建exe文件

我的代码使用pylsd,但pyinstaller无法导入包。 当我尝试运行exe文件时,它显示:

Traceback (most recent call last):
File "final_lines.py", line 4, in <module>
   from pylsd.lsd import lsd
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
File "site-packages\pylsd\__init__.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\lsd.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\bindings\__init__.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\bindings\lsd_ctypes.py", line 56, in <module>
ImportError: Cannot load dynamic library. Did you compile LSD?
[13252] Failed to execute script final_lines

这不起作用。

我使用以下命令为我的程序生成了spec文件:

pyi-makespec --onefile final_lines.py
并添加lsd.dll二进制文件,然后使用以下命令生成exe:

pyinstaller --onefile final_lines.spec
等级库文件的最终版本如下所示:

 # -*- mode: python -*-

block_cipher = None


a = Analysis(['final_lines.py'],
    pathex=['C:\\Users\\yash.sharma\\Desktop\\text\\obj'],
    binaries= [('C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\lib\\win32\\x64\\lsd.dll', '.')],
    datas=[],
    hiddenimports=['C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\bindings\\lsd_ctypes.py'],
    hookspath=[],
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)

exe = EXE(pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    name='final_lines',
    debug=False,
    strip=False,
    upx=True,
    runtime_tmpdir=None,
    console=True )
我的代码文件名是final_lines.py。现在exe工作正常。我不知道细节,但事实证明,你必须单独添加.dll文件,因为pyinstaller本身并不包含它们

 # -*- mode: python -*-

block_cipher = None


a = Analysis(['final_lines.py'],
    pathex=['C:\\Users\\yash.sharma\\Desktop\\text\\obj'],
    binaries= [('C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\lib\\win32\\x64\\lsd.dll', '.')],
    datas=[],
    hiddenimports=['C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\bindings\\lsd_ctypes.py'],
    hookspath=[],
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)

exe = EXE(pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    name='final_lines',
    debug=False,
    strip=False,
    upx=True,
    runtime_tmpdir=None,
    console=True )