Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmcv _file2dict shutil.copyfile PermissionError: [Errno 13] Permission denied #2926

Closed
yg2024 opened this issue Jun 7, 2020 · 5 comments
Closed
Labels

Comments

@yg2024
Copy link

yg2024 commented Jun 7, 2020

import matplotlib; matplotlib.use('Agg')
Traceback (most recent call last):
File "demo/image_demo.py", line 26, in
main()
File "demo/image_demo.py", line 18, in main
model = init_detector(args.config, args.checkpoint, device=args.device)
File "d:\python\pycharm\pycharmprojects\mmdetection\mmdet\apis\inference.py", line 28, in init_detector
config = mmcv.Config.fromfile(config)
File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 165, in fromfile
cfg_dict, cfg_text = Config._file2dict(filename)
File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 92, in _file2dict
osp.join(temp_config_dir, temp_config_name))
File "D:\python\Python36\lib\shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\Users\XXX\AppData\Local\Temp\tmp_lu6u3id\tmpo9exnnds.py'

@hellock hellock added the windows label Jun 7, 2020
@nothingws
Copy link

import matplotlib; matplotlib.use('Agg')
Traceback (most recent call last):
File "demo/image_demo.py", line 26, in
main()
File "demo/image_demo.py", line 18, in main
model = init_detector(args.config, args.checkpoint, device=args.device)
File "d:\python\pycharm\pycharmprojects\mmdetection\mmdet\apis\inference.py", line 28, in init_detector
config = mmcv.Config.fromfile(config)
File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 165, in fromfile
cfg_dict, cfg_text = Config._file2dict(filename)
File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 92, in _file2dict
osp.join(temp_config_dir, temp_config_name))
File "D:\python\Python36\lib\shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\Users\XXX\AppData\Local\Temp\tmp_lu6u3id\tmpo9exnnds.py'

I have the same problem. Have you solved it

@aligoglos
Copy link

I've got same error too !!!

@aligoglos
Copy link

I've solved it with these tricks : (its not good way but you could run it!)

  1. first change config.py by replacing these lines:
            with tempfile.TemporaryDirectory() as temp_config_dir:
                temp_config_file = tempfile.NamedTemporaryFile(
                    dir=temp_config_dir, suffix='.py')
                temp_config_name = osp.basename(temp_config_file.name)
                des = osp.join(temp_config_dir, temp_config_name).replace('\\', '/')
                shutil.copyfile(filename,des)
                temp_module_name = osp.splitext(temp_config_name)[0]
                sys.path.insert(0, temp_config_dir)
                mod = import_module(temp_module_name)
                sys.path.pop(0)
                cfg_dict = {
                    name: value
                    for name, value in mod.__dict__.items()
                    if not name.startswith('__')
                }
                delete imported module
                del sys.modules[temp_module_name]
                close temp file
                temp_config_file.close()

with:

            mod = import_module('DetectoRS')
            sys.path.pop(0)
            cfg_dict = {
               name: value
               for name, value in mod.__dict__.items()
               if not name.startswith('__')
            }

and then copy config fime behind webcam_demo.py and renamed it with DetectoRS.py

@nekitmm
Copy link

nekitmm commented Jun 11, 2020

Also got this problem. No idea what is the cause of this, but I solved it by changing two lines

This:
temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py')

changed to this:
temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='')

And:
shutil.copy(filename, osp.join(temp_config_dir, temp_config_name))

To:
shutil.copy(filename, osp.join(temp_config_dir, temp_config_name) + '.py')

No idea what is going on, but whenever suffix argument is different from actual file extension - everything works and every time file extension is the same as suffix argument I get this permission denied error.

@TimothyZero
Copy link

TimothyZero commented Jun 14, 2020

replace :

tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py')

with

tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py', delete=False)

it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants