# Buggy code
def update_prefix(path, new_prefix, placeholder=prefix_placeholder, mode="text"):
    if on_win:
        # force all prefix replacements to forward slashes to simplify need to escape backslashes
        # replace with unix-style path separators
        new_prefix = new_prefix.replace("\\", "/")

    path = os.path.realpath(path)
    with open(path, "rb") as fi:
        original_data = data = fi.read()

    data = replace_prefix(mode, data, placeholder, new_prefix)
    if not on_win:
        data = replace_long_shebang(mode, data)

    if data == original_data:
        return
    st = os.lstat(path)
    # Remove file before rewriting to avoid destroying hard-linked cache
    os.remove(path)
    with open(path, "wb") as fo:
        fo.write(data)
    os.chmod(path, stat.S_IMODE(st.st_mode))


# Traceback (PermissionError)
prepending C:\\Users\\Alessandro\\Anaconda3 and C:\\Users\\Alessandro\\Anaconda3
\\Library\\mingw-w64\\bin and C:\\Users\\Alessandro\\Anaconda3\\Library\\usr\\bi
n and C:\\Users\\Alessandro\\Anaconda3\\Library\\bin and C:\\Users\\Alessandro\\
Anaconda3\\Scripts to PATH

((Anaconda3)) C:\Users\Alessandro>conda info
Current conda install:

platform : win-64
conda version : 4.1.0
conda-build version : 1.20.0
python version : 3.5.1.final.0
requests version : 2.9.1
root environment : C:\Users\Alessandro\Anaconda3  (writable)
default environment : C:\Users\Alessandro\Anaconda3
envs directories : C:\Users\Alessandro\Anaconda3\envs
package cache : C:\Users\Alessandro\Anaconda3\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
config file : None
is foreign system : False


((Anaconda3)) C:\Users\Alessandro>conda create --name new_env_3 biopython
Fetching package metadata .......
Solving package specifications .............

Package plan for installation in environment C:\Users\Alessandro\Anaconda3\envs\
new_env_3:

The following NEW packages will be INSTALLED:

biopython:      1.67-np111py35_0
mkl:            11.3.3-1
numpy:          1.11.0-py35_1
pip:            8.1.2-py35_0
python:         3.5.1-4
setuptools:     23.0.0-py35_0
vs2015_runtime: 14.00.23026.0-0
wheel:          0.29.0-py35_0

Proceed ([y]/n)? y

Extracting packages ...
An unexpected error has occurred, please consider sending the            |   0%
following traceback to the conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.


Traceback (most recent call last):
File "C:\Users\Alessandro\Anaconda3\Scripts\conda-script.py", line 5, in <modu
le>
sys.exit(main())
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main.py", line
120, in main
args_func(args, p)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main.py", line
127, in args_func
args.func(args, p)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main_create.py
", line 57, in execute
install(args, parser, 'create')
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\install.py", l
ine 407, in install
execute_actions(actions, index, verbose=not args.quiet)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\plan.py", line 566
, in execute_actions
inst.execute_instructions(plan, index, verbose)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\instructions.py",
line 137, in execute_instructions
cmd(state, arg)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\instructions.py",
line 60, in EXTRACT_CMD
extract(arg)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\install.py", line
821, in extract
os.rename(temp_path, path)
PermissionError: [WinError 5] Accesso negato: 'C:\\Users\\Alessandro\\Anaconda3\
\pkgs\\vs2015_runtime-14.00.23026.0-0.tmp' -> 'C:\\Users\\Alessandro\\Anaconda3\
\pkgs\\vs2015_runtime-14.00.23026.0-0'

((Anaconda3)) C:\Users\Alessandro>

# Fixed code
def update_prefix(path, new_prefix, placeholder=prefix_placeholder, mode="text"):
    if on_win:
        # force all prefix replacements to forward slashes to simplify need to escape backslashes
        # replace with unix-style path separators
        new_prefix = new_prefix.replace("\\", "/")

    path = os.path.realpath(path)
    with open(path, "rb") as fi:
        original_data = data = fi.read()

    data = replace_prefix(mode, data, placeholder, new_prefix)
    if not on_win:
        data = replace_long_shebang(mode, data)

    if data == original_data:
        return
    st = os.lstat(path)
    # Remove file before rewriting to avoid destroying hard-linked cache
    os.remove(path)
    with exp_backoff_fn(open, path, "wb") as fo:
        fo.write(data)
    os.chmod(path, stat.S_IMODE(st.st_mode))