【问题标题】:Pyinstaller does not look for the file inside the Python Virtual EnvironmentPyinstaller 不会在 Python 虚拟环境中查找文件
【发布时间】:2019-01-03 19:30:01
【问题描述】:

我想将 Python 代码转换为独立的可执行文件,该代码使用 numpy、scipy 和 Pymc3 模块。我正在使用 Python 3.6.4。我在 Pycharm IDE 中使用虚拟环境创建了项目。我用来运行pyinstaller的命令如下:

venv/Scripts/pyinstaller --onefile src/POD.py

venv 是存储虚拟环境的文件夹,而 src 是我的 Python 源代码的文件夹,即。 POD.py 被保存。 Pyinstaller 运行得很好会生成一些警告消息,但是当我尝试运行 pyinstaller 生成的可执行文件时,它会抛出错误

   Traceback (most recent call last):
  File "POD.py", line 196, in <module>
  File "POD.py", line 79, in train
  File "Lib\site-packages\theano\tensor\var.py", line 155, in __mul__
  File "Lib\site-packages\theano\gof\op.py", line 615, in __call__
  File "Lib\site-packages\theano\tensor\elemwise.py", line 482, in make_node
  File "Lib\site-packages\theano\tensor\elemwise.py", line 438, in      get_output_info
  File "Lib\site-packages\theano\tensor\elemwise.py", line 157, in __init__
  File "Lib\site-packages\theano\gof\op.py", line 1308, in __init__
  File "Lib\site-packages\theano\gof\op.py", line 1331, in load_c_code
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI126642\\theano\\tensor\\c_code\\dimshuffle.c'
[4756] Failed to execute script POD

似乎它正在尝试在虚拟环境之外查找文件 dimshuffle.c。事实上,我可以看到虚拟环境中有一个文件夹,其中包含 dim_shuffle.c 代码。我可以在以下文件夹的虚拟环境中找到它。

venv/Lib/site-packages/theano/tensor/c_code/dimshuffle,c

我的问题是如何指示 pyinstaller 在虚拟环境文件夹中查找 dimshuffle?

【问题讨论】:

  • 我也有同样的问题!!我已经放弃了 pyinstaller

标签: python-3.x pycharm pyinstaller


【解决方案1】:

你可以,

  1. 通过编辑规范文件扩展 sys.path。

     pyi-makespec --paths=/path/to/thisdir \
             --paths=/path/to/otherdir myscript.py 
  2. 使用规范文件列出隐藏的导入。

更多信息请参考this

【讨论】:

    猜你喜欢
    • 2012-07-24
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多