Search code examples
pythonpycharmadmin

How do I give PyCharm Admin permission?


Having a hard time reading this excel file. I did some googling and it looked like I needed to give PyCharm admin permission. So I exited out and then "ran as administrator". Still having the same error. Not even sure if that the actual problem or if I'm doing something else wrong.

my code

import xlrd

loc = (r"C:\Users\tyler\OneDrive\Documents\GB-NYJ 2002 W17.xlsx")

wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
print(sheet.cell_value(0, 0))

the error

C:\Users\tyler\PycharmProjects\NFLModel\venv\Scripts\python.exe C:/Users/tyler/PycharmProjects/NFLModel/Carson.py
Traceback (most recent call last):
  File "C:/Users/tyler/PycharmProjects/NFLModel/Carson.py", line 10, in <module>
    wb = xlrd.open_workbook(loc)
  File "C:\Users\tyler\PycharmProjects\NFLModel\venv\lib\site-packages\xlrd\__init__.py", line 111, in open_workbook
    with open(filename, "rb") as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\tyler\\OneDrive\\Documents\\GB-NYJ 2002 W17.xlsx'

Process finished with exit code 1

Solution

  • So I got it to work. Unfortunately I'm not 100% sure what exactly the issue was. So I'll just rundown the steps I tool

    1. run pycharm with admin permission
    2. Set Configuration to the file that's running
    3. Create init file

    At this point it was still not working

    1. Restart computer. Then it worked lol

    Someone suggested that Windows could have been running Excel in the background and that was stopping python from accessing the file. Like I said though, can't be 100% that was the sole issue.