我在Anaconda 4.3中使用python 3.4环境,我正在尝试使用py2exe打包使用selenium的python脚本。该脚本完美地作为.py文件运行,但尝试使用import语句从selenium模块导入webdriver时,.exe返回错误:
from selenium import webdriver
这是在控制台中返回的回溯:
Traceback (most recent call last):
File "my_script.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 40, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 25, in <module>
from .webelement import WebElement
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Users\me\.conda\envs\py34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 40, in <module>
getAttribute_js = pkgutil.get_data(__package__, 'getAttribute.js').decode('utf8')
File "C:\Users\me\.conda\envs\py34\lib\pkgutil.py", line 611, in get_data
spec = importlib.util.find_spec(package)
File "C:\Users\me\.conda\envs\py34\lib\importlib\util.py", line 81, in find_spec
fullname = resolve_name(name, package) if name.startswith('.') else name
AttributeError: 'NoneType' object has no attribute 'startswith'
编辑将此短语称为实际问题:将此文件作为.py脚本运行时,此import语句正常工作。为什么这只会在被py2exe打包后发生,并且我在py2exe安装文件中缺少某种选项?