0

Dual os in my pc, window10 + debian,the module analyse works fine in my debian,i copy it into c:\mydoc\analyse,reboot into win10.

import shutil
shutil.copy('c:\mydoc\analyse','C:\Users\pengsir\AppData\Local\Programs\Python\Python37\Lib\site-packages')

It encounter a problem:

  File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

How to copy the directory into my window10's python library?

>>> import  shutil
>>> shutil.copy(r'c:\mydoc\analyse',r'C:\Users\pengsir\AppData\Local\Programs\Python\Python37\Lib\site-packages')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\pengsir\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 248, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Users\pengsir\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
PermissionError: [Errno 13] Permission denied: 'c:\\mydoc\\analyse'

I have run cmd with admin permission.

showkey
  • 482
  • 42
  • 140
  • 295
  • Try to use raw-strings in your path: `shutil.copy(r'c:\mydoc\analyse',r'C:\Users\pengsir\AppData\Local\Programs\Python\Python37\Lib\site-packages')` – Andrej Kesely Jul 30 '20 at 07:28
  • Does this answer your question? [Why do I get a SyntaxError for a Unicode escape in my file path?](https://stackoverflow.com/questions/18084554/why-do-i-get-a-syntaxerror-for-a-unicode-escape-in-my-file-path) – mkrieger1 Jul 30 '20 at 08:32

1 Answers1

0
  1. Escape with \\ --double \.

  2. Use copytree method to copy directory to destination.

    shutil.copytree('c:\\mydoc\\analyse','C:\\Users\\pengsir\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages\\analyse')
    
showkey
  • 482
  • 42
  • 140
  • 295