如何解决autopytoexe中的错误以将python程序编译为exe?

时间:2019-05-31 11:12:36

标签: python-3.x pyinstaller

当我尝试在python 3.7中编译程序时 与:

  1. 自动py-exe v2.6.0

代码是:

from selenium import webdriver
import pathlib
import resource

fn = pathlib.Path(__file__).parent / 'chromedriver.exe'


browser = webdriver.Chrome(fn)
browser.get('website')

# fill in username and hit the next button
username = browser.find_element_by_id('user_login')
username.send_keys('xxxxxxx')

password = browser.find_element_by_id('user_pass')
password.send_keys('xxxxxxxxxx')

nextButton1 = browser.find_element_by_id('wp-submit')
nextButton1.click()

browser.get('website')

nextButton2 = browser.find_element_by_class_name('add-new-h2')
nextButton2.click()

nextButton3 = browser.find_element_by_id('is_continue_no')
nextButton3.click()

nextButton4 = browser.find_element_by_class_name('rad10')
nextButton4.click()

编译错误

An error occurred, traceback follows:
Traceback (most recent call last):
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\auto_py_to_exe-2.6.0-py3.7.egg\auto_py_to_exe\__main__.py", line 259, in convert
    pyi.run() # Execute PyInstaller
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 29, in <module>
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
    strip_binaries=self.strip, upx_binaries=self.upx,
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
    self.__postinit__()
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble
    pylib_name = os.path.basename(bindepend.get_python_library_path())
  File "C:\Users\Jesus-NewPC\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 214, in basename
    return split(p)[1]
  File "C:\Users\Jesus-NewPC\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

all log

我希望编译正确

我尝试

  1. 安装Windows sdk
  2. 安装可视c ++库

需要帮助来解决问题 这是我的python程序中的代码

2 个答案:

答案 0 :(得分:0)

您的代码存在一个问题,就是您试图加载chromedriver.exe,它可以在当前目录中找到,但是冻结后就无法再加载了。如果要使用Pyinstaller冻结应用程序,则首先需要将该文件添加到输出可执行文件中,然后从temp目录中加载它。

我不确定auto-py-to-exe,但是您可以使用下面的代码,然后使用

pyinstaller -F --add-data "chromedriver.exe;." yourscript.py

from selenium import webdriver
import resource
import sys
import os


def resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)

fn = resource_path('chromedriver.exe')

browser = webdriver.Chrome(fn)
browser.get('website')

# fill in username and hit the next button
username = browser.find_element_by_id('user_login')
username.send_keys('xxxxxxx')

password = browser.find_element_by_id('user_pass')
password.send_keys('xxxxxxxxxx')

nextButton1 = browser.find_element_by_id('wp-submit')
nextButton1.click()

browser.get('website')

nextButton2 = browser.find_element_by_class_name('add-new-h2')
nextButton2.click()

nextButton3 = browser.find_element_by_id('is_continue_no')
nextButton3.click()

nextButton4 = browser.find_element_by_class_name('rad10')
nextButton4.click()

答案 1 :(得分:0)

以最简单的方法解决,将带有脚本的proyect文件夹传递给 磁盘C:和错误已解决,但将错误保存到磁盘E: