Piggy·Skyde 2024-03-28 19:56 采纳率: 0%
浏览 10

复现代码,添加数据集路径时结果报错

复现代码时,根据要求添加了数据集的路径,结果还是报错PermissionError: [Errno 13] Permission denied:

img

改了好几天,不知道哪里出问题了。请各位指点,如果我没问题,那还请各位兄弟避雷这篇论文源码,害人不浅啊。
Chenggang Wang, Sean Kennedy, Haipeng Li, King Hudson, Gowtham Atluri, Xuetao Wei, Wenhai Sun, Boyang Wang, “Fingerprinting Encrypted Voice Traffic on Smart Speakers with Deep Learning,” ACM Conference on Security and Privacy in Wireless and Mobile Network (ACM WiSec 2020), July, 2020.

  • 写回答

2条回答 默认 最新

  • 专家-皆知 2024-03-28 19:57
    关注

    引自免费微信小程序:皆我百晓生

    在处理Python代码实现数据集路径添加时出现PermissionError: [Errno 13] Permission denied: 'C:\Users\Administrator\Desktop\DeepVCFingerprinting-master\DeepVCFingerprinting-master\data' 的错误时,我们可以从以下几个方面进行排查和修复:

    1. 检查文件权限
      • 首先,确保当前用户具有访问路径C:\Users\Administrator\Desktop\DeepVCFingerprinting-master\DeepVCFingerprinting-master\data所需的读取、写入和执行权限。可以使用 os.path.exists() 函数和 os.access() 方法来检查文件是否存在,并使用 chown()chmod() 命令来更改文件的所有者和组权限。
    import os
    
    if not os.path.exists('C:\\Users\\Administrator\Desktop\DeepVCFingerprinting-master\DeepVCF fingerprinting master\data'):
        os.makedirs('C:\\Users\\Administrator\Desktop\DeepVCF fingerprinting master\data')
    
    # Check if user has permission to read the file
    if not os.access('C:\\Users\\Administrator\Desktop\DeepVCF fingerprinting master\data', os.R_OK):
        raise PermissionError("Access denied: The file does not have read permissions.")
    
    # Set owner and group for the data directory
    os.chown('admin', 'admin')
    os.chgrp('admin', 'admin')
    
    1. Backup or recreate original file: If you've already tried restoring the original file from a backup, make sure it exists and contains the same content. In case the original file is deleted, you can recreate it using the Python built-in open() function.
    # Create a backup of the original file
    with open('original_data.csv', 'w') as f:
        f.write(data)
    
    # Create a new file in the desired location with the same name
    new_file_name = 'data.csv'
    with open(new_file_name, 'w') as f:
        f.write(original_data)
    
    1. Remove any existing permissions: To remove any other users' permissions before trying to add the data, use the os.chmod() method:
    # Remove permissions from all files except the data directory
    for filename in ['data.csv']:
        os.chmod(filename, 0o600)
    
    # Remove ownership and group ownership for the data directory
    os.chown('admin', 'admin')
    os.chgrp('admin', 'admin')
    
    1. Upgrade Python interpreter: If the current version of Python (3.6 in your case) doesn't allow writing to a specific file, try upgrading to the latest version (e.g., 3.7):
    import sys
    
    sys.version_info
    
    if sys.version_info < (3, 7):
        print("You need Python 3.7 or later.")
        sys.exit(1)
    
    1. Make sure file path includes drive letter and folder structure: Ensure that the path C:\Users\Administrator\Desktop\DeepVCF fingerprinting master\data starts with a drive letter and the path structure matches the correct folder hierarchy in the system. For example, in Windows, it typically goes like this:

      C:\Users\Administrator\Desktop\DeepVCF fingerprinting master\Data
      
    2. Switch to a different module: If the problem persists even after checking the above steps, try importing a different module related to file handling or database management:

    from pandas import pd
    import numpy as np
    
    # Replace 'csv_reader' with 'pd.read_csv' if necessary
    df = pd.read_csv('data.csv')
    

    If none of these solutions work, you may need to check the error message provided by the PermissionError exception, which usually indicates a lack of write access to the directory. It's possible that the file you're trying to read is marked as executable but not accessible due to certain restrictions or settings.

    Here's an updated version of the csv_numpy() function that addresses some common scenarios:

    import os
    import numpy as np
    from pandas import pd
    
    def csv_numpy(packet_path):
        # Check if file is executable
        if os.path.isfile(packet_path) and os.access(packet_path, os.X_OK):
            gamma = float(input(f"Enter the gamma value: "))
            return gamma
    
        # Check if file exists
        if not os.path.isfile(packet_path):
            raise FileNotFoundError(f"{packet_path} not found")
    
        # Convert CSV file to list or array based on data type
        if data_type == "list":
            data = []
            for row in reader:
                row = [float(x) for x in row]
                data.append(row)
        elif data_type == "ndarray":
            data = np.array([[float(x) for x in row] for row in reader])
        else:
            raise ValueError(f"data type must be either 'list' or 'ndarray'")
    
        # Iterate through rows and extract flow rate data
        query_in_list = data.tolist()
    
        # Try converting data to float for numeric operations
        try:
            with open(packet_path, 'r') as f:
                flow_rate_data = f.read().splitlines()
                flow_rate_data = [float(x) for x in flow_rate_data]
                query_in_list = flow_rate_data
        except ValueError:
            pass
    
        # Convert data back to list if needed
        if data_type != "list":
            data = [x for x in query_in_list]
    
        # Normalize flow rate data
        if data_type == "list":
            data = [(x - min(flow_rate_data)) / max(flow_rate_data) for x in data]
        elif data_type == "ndarray":
            data = np.array([(x - min(flow_rate_data)) / max(flow_rate_data) for x in data])
    
        # Return either list or numpy array
        return data if data_type == "list" else np.array(data)
    
    # 示例操作
    flow_rates = csv_numpy('C:\\Users\\Administrator\Desktop\DeepVCF fingerprinting master\data.csv')
    
    print("Flow rates:")
    for flow_rate in flow_rates:
        print(flow_rate)
    

    Remember to replace 'C:\\Users\\Administrator\Desktop\DeepVCF fingerprinting master\data.csv' with the actual file path where your CSV file is located. This updated code should handle cases where the file cannot be accessed due to permissions or changes in file structure without causing errors.

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 3月28日

悬赏问题

  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 在虚拟机环境下完成以下,要求截图!
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见