0

Problem

I am getting permission errors and code inconsistencies using Pycharm with Windows 10. I can use this piece of code on my windows 10 desktop, but it doesn't work on my Surface 4:

xlsx = pd.ExcelFile('\test\Participant01Master.xlsx')

Please note the folder and file is in my PyCharm IDE project. I am using pandas for the code given above. However, the error given to me is:

FileNotFoundError: [Errno 2] No such file or directory: '/test/Participant01Master.xlsx'

I thought maybe something was funky with my xlrd dependency. So, I tried uninstalling the xlrd package (to reinstall) and I got the following: enter image description here

Attempted Solutions

I can successfully use the code df = pd.read_excel(open('C:\\Users\hlyates\Source\Repos\Project0\Data\Participant01Master.xlsx','rb')) to read my file. However, this feels gross because my xlxs line of code works for one machine and not another?

As for the path, I verified PyCharm is in the Administrators Group and that my user profile has the same rights and special access.

Summary

This really kills my enthusiam for the Windows ecosystem? I don't feel PyCharm is working as intended on my Windows 10 box. I should not have to right click and 'run as administrator' when PyCharm admin (which seems to fix some of the weird file permission issues) when I and admin group already have permissions to this. I also think it is weird that code will work for my IDE on my desktop, but not Surface 4. I don't fight Linux like I do Windows with this stuff. I only shared both these issues because I feel they could be related? If I am doing something stupid, by all means point this out and I will correct it, but I'm doing the best I can with the information I have provided. Thanks for your patience. :)

References

I was using code found here for testing.

Community
  • 1
  • 1
hlyates
  • 1,279
  • 3
  • 22
  • 44
  • Thanks. These are useful comments. I noted the code I wrote works in main, but not in helper.py files. Not sure why that is. – hlyates Apr 13 '16 at 15:26

3 Answers3

3

You should just install Python not in 'Program Files' folder, try 'C:\Python\python35-32\' and everything will be fine. If you want more details, please check this topic.

There is too much hype about Windows 10, actually there is nothing so special.

Hatari
  • 31
  • 2
0

One problem that could be happening is the issues with the file separators. It looks like you are using back slashes in your path name. Python treats '\' as an escape character. To normalize your file path (independent of OS), use use os.path.normpath to convert the slash to the the file separator used by your current OS:

xlsx = pd.ExcelFile(os.path.normpath('\test\Participant01Master.xlsx'))

an alternative can use os.sep in place of the slash. This will use the correct file separator for the OS python is running on:

xlsx = pd.ExcelFile('{0}test{0}Participant01Master.xlsx'.format(os.sep))

References: os path docs: https://docs.python.org/2/library/os.path.html#os.path.normpath

os sep doc: https://docs.python.org/2/library/os.html#os.sep

blog on python file paths: https://pythonconquerstheuniverse.wordpress.com/2008/06/04/gotcha-%E2%80%94-backslashes-in-windows-filenames/

asharon.mori
  • 105
  • 2
  • 9
0

I'm using pycharm in windows 10 to find files in any system I use the next:

from os.path import expanduser, join, dirname, abspath
home = expanduser("~")  # this is the path to the home folder of the current user
curdir = dirname(abspath(__file__))  # This one returns the path to the file that is running
filepath = join (curdir, 'filename.txt')  # This one joins the path of my current directory to a file name (or any other path) independent of the system

I have tested this and works in Linux and Windows

Miguel
  • 1
  • 1