(vpy35) C:\Users\John>conda install qt -v
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\Anaconda3\envs\vpy35:
The following NEW packages will be INSTALLED:
qt: 5.6.2-vc14_3 [vc14]
Proceed ([y]/n)?
()
===> LINKING PACKAGE: defaults::qt-5.6.2-vc14_3 <===
prefix=C:\Anaconda3\envs\vpy35
source=C:\Anaconda3\pkgs\qt-5.6.2-vc14_3
An error occurred while installing package 'defaults::qt-5.6.2-vc14_3'.
UnicodeDecodeError('utf-8', b'\xd2\xd1\xb8\xb4\xd6\xc6 1 \xb8\xf6\xce\xc4\xbc\xfe\xa1\xa3\r\n', 0, 1, 'invalid c
ontinuation byte')
Attempting to roll back.
===> REVERSING PACKAGE LINK: defaults::qt-5.6.2-vc14_3 <===
prefix=C:\Anaconda3\envs\vpy35
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:
https://github.com/conda/conda/issues
overtaking stderr and stdout
stderr and stdout yielding back
Current conda install:
platform : win-64
conda version : 4.3.9
conda is private : False
conda-env version : 4.3.9
conda-build version : not installed
python version : 3.6.0.final.0
requests version : 2.12.4
root environment : C:\Anaconda3 (writable)
default environment : C:\Anaconda3\envs\vpy35
envs directories : C:\Anaconda3\envs
package cache : C:\Anaconda3\pkgs
channel URLs : https://conda.anaconda.org/anaconda-fusion/win-64
https://conda.anaconda.org/anaconda-fusion/noarch
https://repo.continuum.io/pkgs/free/win-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/win-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/win-64
https://repo.continuum.io/pkgs/pro/noarch
https://repo.continuum.io/pkgs/msys2/win-64
https://repo.continuum.io/pkgs/msys2/noarch
config file : C:\Users\John\.condarc
offline mode : False
user-agent : conda/4.3.9 requests/2.12.4 CPython/3.6.0 Windows/7 Windows/6.1.7601
`$ C:\Anaconda3\Scripts\conda-script.py install qt -v`
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 309, in _execute_actions
run_script(target_prefix, Dist(pkg_data), 'post-unlink' if is_unlink else 'post-link')
File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 480, in run_script
subprocess_call(command_args, env=env)
File "C:\Anaconda3\lib\site-packages\conda\gateways\subprocess.py", line 61, in subprocess_call
return Response(ensure_text_type(stdout), ensure_text_type(stderr), int(rc))
File "C:\Anaconda3\lib\site-packages\conda\common\compat.py", line 155, in ensure_text_type
return value.decode('utf-8') if hasattr(value, 'decode') else value
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 0: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 262, in execute
pkg_data, actions)
File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 326, in _execute_actions
reverse_excs,
conda.CondaMultiError: 'utf-8' codec can't decode byte 0xd2 in position 0: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\conda\exceptions.py", line 616, in conda_exception_handler
return_value = func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
exit_code = args.func(args, p)
File "C:\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 80, in execute
install(args, parser, 'install')
File "C:\Anaconda3\lib\site-packages\conda\cli\install.py", line 359, in install
execute_actions(actions, index, verbose=not context.quiet)
File "C:\Anaconda3\lib\site-packages\conda\plan.py", line 837, in execute_actions
execute_instructions(plan, index, verbose)
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 258, in execute_instructions
cmd(state, arg)
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 119, in UNLINKLINKTRANSACTION_CMD
txn.execute()
File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 278, in execute
rollback_excs,
conda.CondaMultiError: 'utf-8' codec can't decode byte 0xd2 in position 0: invalid continuation byte
报错的代码为File "C:\Anaconda3\lib\site-packages\conda\core\link.py", line 278, in execute
def execute(self):
if not self._verified:
self.verify()
pkg_idx = 0
try:
for pkg_idx, (pkg_data, actions) in enumerate(self.all_actions):
self._execute_actions(self.target_prefix, self.num_unlink_pkgs, pkg_idx,
pkg_data, actions)
except Exception as execute_multi_exc:
# reverse all executed packages except the one that failed
rollback_excs = []
if context.rollback_enabled:
failed_pkg_idx = pkg_idx
reverse_actions = self.all_actions[:failed_pkg_idx]
for pkg_idx, (pkg_data, actions) in reversed(tuple(enumerate(reverse_actions))):
excs = self._reverse_actions(self.target_prefix, self.num_unlink_pkgs,
pkg_idx, pkg_data, actions)
rollback_excs.extend(excs)
raise CondaMultiError(tuple(concatv(
(execute_multi_exc.errors
if isinstance(execute_multi_exc, CondaMultiError)
else (execute_multi_exc,)),
rollback_excs,
)))
else:
for pkg_idx, (pkg_data, actions) in enumerate(self.all_actions):
for axn_idx, action in enumerate(actions):
action.cleanup()
@staticmethod
def _execute_actions(target_prefix, num_unlink_pkgs, pkg_idx, pkg_data, actions):
axn_idx, action, is_unlink = 0, None, True
try:
dist = Dist(pkg_data)
is_unlink = pkg_idx <= num_unlink_pkgs - 1
if is_unlink:
log.info("===> UNLINKING PACKAGE: %s <===\n"
" prefix=%s\n",
dist, target_prefix)
else:
log.info("===> LINKING PACKAGE: %s <===\n"
" prefix=%s\n"
" source=%s\n",
dist, target_prefix, pkg_data.extracted_package_dir)
run_script(target_prefix if is_unlink else pkg_data.extracted_package_dir,
Dist(pkg_data),
'pre-unlink' if is_unlink else 'pre-link',
target_prefix)
for axn_idx, action in enumerate(actions):
action.execute()
run_script(target_prefix, Dist(pkg_data), 'post-unlink' if is_unlink else 'post-link')
except Exception as e: # this won't be a multi error
# reverse this package
log.debug("Error in action #%d for pkg_idx #%d %r", axn_idx, pkg_idx, action)
log.debug(format_exc())
reverse_excs = ()
if context.rollback_enabled:
log.error("An error occurred while %s package '%s'.\n"
"%r\n"
"Attempting to roll back.\n",
'uninstalling' if is_unlink else 'installing', Dist(pkg_data), e)
reverse_excs = UnlinkLinkTransaction._reverse_actions(
target_prefix, num_unlink_pkgs, pkg_idx, pkg_data, actions,
reverse_from_idx=axn_idx
)
raise CondaMultiError(tuple(concatv(
(e,),
reverse_excs,
)))
错误是由执行了.qt-post-link.bat后产生
def run_script(prefix, dist, action='post-link', env_prefix=None):
"""
call the post-link (or pre-unlink) script, and return True on success,
False on failure
"""
path = join(prefix,
'Scripts' if on_win else 'bin',
'.%s-%s.%s' % (dist.name, action, 'bat' if on_win else 'sh'))
if not isfile(path):
return True
env = os.environ.copy()
if action == 'pre-link':
is_old_noarch = False
try:
with open(path) as f:
script_text = ensure_text_type(f.read())
if "This is code that is added to noarch Python packages." in script_text:
is_old_noarch = True
except Exception as e:
import traceback
log.debug(e)
log.debug(traceback.format_exc())
env['SOURCE_DIR'] = prefix
if not is_old_noarch:
warnings.warn(dals("""
Package %s uses a pre-link script. Pre-link scripts are potentially dangerous.
This is because pre-link scripts have the ability to change the package contents in the
package cache, and therefore modify the underlying files for already-created conda
environments. Future versions of conda may deprecate and ignore pre-link scripts.
""" % dist))
if on_win:
try:
command_args = [os.environ[str('COMSPEC')], '/c', path]
except KeyError:
log.info("failed to run %s for %s due to COMSPEC KeyError", action, dist)
return False
else:
shell_path = '/bin/sh' if 'bsd' in sys.platform else '/bin/bash'
command_args = [shell_path, "-x", path]
env['ROOT_PREFIX'] = context.root_prefix
env['PREFIX'] = env_prefix or prefix
env['PKG_NAME'] = dist.name
env['PKG_VERSION'] = dist.version
env['PKG_BUILDNUM'] = dist.build_number
try:
log.debug("for %s at %s, executing script: $ %s",
dist, env['PREFIX'], ' '.join(command_args))
subprocess_call(command_args, env=env)
except CalledProcessError as e:
m = messages(prefix)
if action in ('pre-link', 'post-link'):
if 'openssl' in text_type(dist):
# this is a hack for conda-build string parsing in the conda_build/build.py
# create_env function
message = "%s failed for: %s" % (action, dist)
else:
message = dals("""
%s script failed for package %s
running your command again with `-v` will provide additional information
location of failed script: %s
==> script messages <==
%s
""") % (action, dist, path, m or "")
raise LinkError(message)
else:
log.warn("%s script failed for package %s\n"
"consider notifying the package maintainer", action, dist)
return False
else:
messages(prefix)
return True
在文件C:\Anaconda3\Lib\site-packages\conda\gateways\subprocess.py中
def subprocess_call(command, env=None, path=None, stdin=None, raise_on_error=True):
"""This utility function should be preferred for all conda subprocessing.
It handles multiple tricky details.
"""
env = {str(k): str(v) for k, v in iteritems(env if env else os.environ)}
path = sys.prefix if path is None else abspath(path)
log.debug("executing>> %s", ' '.join(command))
p = Popen(_split_on_unix(command) if isinstance(command, string_types) else command,
cwd=path, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env)
ACTIVE_SUBPROCESSES.add(p)
stdin = ensure_binary(stdin) if isinstance(stdin, string_types) else None
stdout, stderr = p.communicate(input=stdin)
rc = p.returncode
ACTIVE_SUBPROCESSES.remove(p)
if raise_on_error and rc != 0:
log.info(_format_output(command, path, rc, stdout, stderr))
raise CalledProcessError(rc, command,
output=_format_output(command, path, rc, stdout, stderr))
if log.isEnabledFor(TRACE):
log.trace(_format_output(command, path, rc, stdout, stderr))
return Response(ensure_text_type(stdout), ensure_text_type(stderr), int(rc))
C:\Anaconda3\Lib\site-packages\conda\common\compat.py
def ensure_text_type(value):
return value.decode('utf-8') if hasattr(value, 'decode') else value
b'\xd2\xd1\xb8\xb4\xd6\xc6 1 \xb8\xf6\xce\xc4\xbc\xfe\xa1\xa3\r\n'
在函数subprocess_call最后使用来避免此错误
try:
return Response(ensure_text_type(stdout), ensure_text_type(stderr), int(rc))
except Exception as e:
return Response((stdout), (stderr), int(rc))