【问题标题】:Pyinstaller "ValueError: Can't mix absolute and relative paths"Pyinstaller“ValueError:不能混合绝对路径和相对路径”
【发布时间】:2020-04-14 06:14:29
【问题描述】:

我正在使用 Windows 10 和 anaconda3 来管理我的 python 包。这是我第一次使用python,我正在尝试用pyqt5制作我自己的gui程序。另外我正在尝试使用 Pyinstaller 制作 .exe 文件。我遇到的问题是 .exe 正在抛出错误块:

(pyqt5_env) C:\Python Projects>pyinstaller -w -F App_ver05.py
268 INFO: PyInstaller: 4.0.dev0+b3dd91c8a8
268 INFO: Python: 3.7.7 (conda)
268 INFO: Platform: Windows-10-10.0.18362-SP0
Traceback (most recent call last):
  File "c:\anaconda3\envs\pyqt5_env\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\anaconda3\envs\pyqt5_env\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Anaconda3\envs\pyqt5_env\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\__main__.py", line 112, in run
    spec_file = run_makespec(**vars(args))
  File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\__main__.py", line 58, in run_makespec
    spec_file = PyInstaller.building.makespec.main(filenames, **opts)
  File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 458, in main
    specfile.write(onefiletmplt % d)
  File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 101, in __repr__
    self.variable_prefix, self.filename_suffix = make_variable_path(self.path)
  File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 84, in make_variable_path
    if os.path.commonpath([filename, from_path]) == from_path:
  File "c:\anaconda3\envs\pyqt5_env\lib\ntpath.py", line 615, in commonpath
    raise ValueError("Can't mix absolute and relative paths") from None
ValueError: Can't mix absolute and relative paths

无论使用哪个 .py 文件,都会发生相同的错误。有关信息,我在下面编写了使用的代码。

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout


class MyApp(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        btn1 = QPushButton('&Button1', self)
        btn1.setCheckable(True)
        btn1.toggle()

        vbox = QVBoxLayout()
        vbox.addWidget(btn1)

        self.setLayout(vbox)
        self.setWindowTitle('QPushButton')
        self.setGeometry(300, 300, 300, 200)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())

我卸载并重新安装了 pyinstaller,但它没有工作。我不认为这是代码问题,因为代码非常简单。谁能给出这个问题的解决方案或提示?

【问题讨论】:

    标签: python-3.x pyinstaller


    【解决方案1】:

    发生在我身上的是绝对路径名中有一个空格。一旦项目被移动到一个没有空格的目录,它就可以构建了

    【讨论】:

    • 你是对的。实际上,在应用 gupta 的解决方案之前,我将我的 .py 文件移动到了另一个名称中没有空格的文件夹,并且它起作用了。感谢您的评论!
    【解决方案2】:

    这个问题的解决方法是使用完整的文件名,并在文件名后附加标志-F。例如,在您的情况下,如果文件 App_ver05.py 的绝对路径是:

    /home/user123/Desktop/文件夹名/App_ver05.py

    然后使用命令:

    pyinstaller -F /home/user123/Desktop/foldername/App_ver05.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-16
      • 2010-09-15
      • 2013-07-14
      • 2010-12-17
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      • 2011-06-30
      相关资源
      最近更新 更多