当我还有3.5时,如何让pyinstaller使用python 2.7?

时间:2016-12-20 18:24:51

标签: python pyinstaller

它似乎自动使用最新版本,我无法在pyinstaller文档中找到答案。
它抱怨我的python2代码语法不正确,但它没有。

    Traceback (most recent call last):
      File "/usr/bin/pyinstaller", line 11, in <module>
        load_entry_point('PyInstaller==3.2', 'console_scripts', 'pyinstaller')()
      File "/usr/lib/python3.5/site-packages/PyInstaller/__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/usr/lib/python3.5/site-packages/PyInstaller/__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/usr/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/usr/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "/usr/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 212, in __init__
    self.__postinit__()
  File "/usr/lib/python3.5/site-packages/PyInstaller/building/datastruct.py", line 178, in __postinit__
    self.assemble()
  File "/usr/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 413, in assemble
    priority_scripts.append(self.graph.run_script(script))
  File "/usr/lib/python3.5/site-packages/PyInstaller/depend/analysis.py", line 144, in run_script
    self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
  File "/usr/lib/python3.5/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 888, in run_script
    co_ast = compile(contents, pathname, 'exec', ast.PyCF_ONLY_AST, True)
  File "/home/chuck/Pictures/testpics/photoresize.py", line 59
    print "incorrect options please choose from d(irectory),s(ize),e(xtension),r(ecursive) or use defaults"
                                                                                                          ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:0)

也许使用virtualenvvirtualenvwrapper 使用virtualenv,可以使用不同版本的Python创建单独的环境。 virtualenvwrapper是virtualenv的包装器,它更容易使用。

答案 1 :(得分:0)

由于您不愿意像评论那样安装虚拟环境,因此可以采用以下方法:

  1. 找到安装python 2.x的路径:(不确定):/usr/local/lib/python2.7
  2. 打开控制台
  3. 输入PATH=/usr/local/lib/python2.7:$PATH
  4. 键入python --version只是为了检查它是否说V2不是V3
  5. 使用python前缀
  6. 运行您的pyinstaller可执行文件

    这不会影响系统路径(控制台的本地路径),因此无需恢复到以前的路径设置。完成后关闭控制台。

    另外,请不要使用sudo,因为它不需要它会更改/重置路径,这是您确认时的问题。