cx_freeze exe文件在anaconda提示符下起作用,但在Windows cmd命令提示符下不起作用? [英] cx_freeze exe file works in anaconda prompt but not in windows cmd command prompt?

查看:324
本文介绍了cx_freeze exe文件在anaconda提示符下起作用,但在Windows cmd命令提示符下不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了大部分时间试图从我的python脚本编译一个exe文件,并通过vanilla cmd命令提示符运行它.我终于设法创建了exe文件,但是很奇怪,它只在anaconda提示符下运行,而不在cmd中运行.

I have spent most of the day trying to compile an exe file from my python script and running it through the vanilla cmd command prompt. I finally managed to create the exe-file, but weirdly it only runs in the anaconda prompt and not in the cmd.

这是完整的错误消息/回溯:

Here is the full error message/traceback:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "generateKonsekvens.py", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\__init__.py", line 1, in <module>
    from geopandas.geoseries import GeoSeries
  File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geoseries.py", line 7, in <module>
    from shapely.geometry import shape, Point
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\__init__.py", line 4, in <module>
    from .base import CAP_STYLE, JOIN_STYLE
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\base.py", line 17, in <module>
    from shapely.coords import CoordinateSequence
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\coords.py", line 8, in <module>
    from shapely.geos import lgeos
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geos.py", line 130, in <module>
    os.path.join(sys.prefix, "Library", "lib", "geos_c.dll"),
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geos.py", line 56, in load_dll
    libname, fallbacks or []))
OSError: Could not find lib geos_c.dll or load any of its variants ['Library\\lib\\geos_c.dll'].

如您所见,它似乎是在anaconda文件夹中寻找东西-这与冻结脚本的目的背道而驰. geos_c.dll文件属于fiona/shapely,在这种情况下,它们是geopandas模块的依赖项.可以在已编译的文件夹(lib/shapely)中找到geos_c.dll文件.

As you can see, it seems to be loking for something in the anaconda folder - which defeats the purpose of freezing the script. The geos_c.dll file belongs to fiona/shapely, which are in this case dependencies of the geopandas module. The geos_c.dll file can be found in the compiled folder (lib/shapely).

该脚本在正常的命令提示符下使用可以正常运行

The script runs just fine in the normal command prompt using

python generateKonsekvens.py

在文件夹中.

是什么原因造成的,该如何解决?

What is causing this, and how do I fix it?

Python 3.6.3,Windows 10 64位.

Python 3.6.3, windows 10 64 bit.

更新

我尝试了jpeg的建议,但都没有用(在那些位置找不到dll).我尝试了手动将dll复制到Library/lib/geos_c.dll的临时解决方案,该操作将某些文件复制了过来,但是给出了相同的错误.然后,我尝试使用build_exe_options = {'include_files': [(os.path.join(sys.prefix, "Library", "bin", "geos_c.dll"), os.path.join("Library", "bin", "geos_c.dll"))]},它在anaconda目录中找到了geos_c.dll文件.这次我也通过Windows cmd打包了它,并且包含了dll.但是,错误仍然存​​在...我现在将尝试使用新的新鲜conda anaconda venv,但同时也欢迎其他任何想法.

I tried the suggestions of jpeg, and none of them worked (could not find the dll at those locations). I tried an adhoc-solution of manually copying the dll to Library/lib/geos_c.dll, which copied some files over, but gives the same error. I then tried with build_exe_options = {'include_files': [(os.path.join(sys.prefix, "Library", "bin", "geos_c.dll"), os.path.join("Library", "bin", "geos_c.dll"))]}, which finds the geos_c.dll file in the anaconda directory. I also packaged it through the windows cmd this time, and the dlls are included. The error, however, remains the same... I will now try with a new, fresh conda anaconda venv, but any other ideas are welcome in the meanwhile.

推荐答案

问题可能是由于可执行文件正在寻找Library/lib/geos_c.dll(由于Anaconda封装shapely的方式)但DLL被打包的事实按cx_Freeze进入lib/shapely/geos_c.dll(可能是如果使用pip安装shapely时的情况).当您从Anaconda提示符运行可执行文件时,回退将在Anaconda库路径中找到DLL,但是如果您从cmd朗姆酒,则此回退将不起作用,因为在cmd路径中找不到DLL的副本.

The problem is probably due to the fact that the executable is looking for Library/lib/geos_c.dll (due to the way Anaconda packages shapely) but the DLLs gets packaged by cx_Freeze into lib/shapely/geos_c.dll (probably as it would be if shapely would have been installed using pip). When you run your executable from the Anaconda prompt, the fallback finds the DLL in the Anaconda library path, but if you rum from cmd, this fallback does not work as no copy of the DLL is found in the cmd path.

尝试将DLL手动包含在安装目录中,然后回退可能会起作用.您可以使用安装脚本中的build_exe选项include_files来完成此操作:

Try to manually include the DLL in the installation directory, the fallback will probably work then. You can do this using the build_exe option include_files in your setup script:

import os
import sys
build_exe_options = {'include_files': [os.path.join(sys.prefix, "Library", "lib", "geos_c.dll")]}

...

setup(...
      options = {'build_exe': build_exe_options},
      ...)

如果这不起作用,请尝试

If this does not work, try with

build_exe_options = {'include_files': [(os.path.join(sys.prefix, "Library", "lib", "geos_c.dll"), os.path.join("lib", "geos_c.dll"))]}

如果这还是行不通的,请尝试

If this also does not work, try with

build_exe_options = {'include_files': [(os.path.join(sys.prefix, "Library", "lib", "geos_c.dll"), os.path.join("Library", "lib", "geos_c.dll"))]}

这篇关于cx_freeze exe文件在anaconda提示符下起作用,但在Windows cmd命令提示符下不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆