0

I am trying to run the code as listed on Github, https://github.com/duytinvo/ijcai2015. However, after running the command: python targetdep+.py, I received the following error:

IOError: [Errno 13] Permission denied: '../data/output/training'

This is the part of the code that caused the error:

def writevec(filename,x,y):
f=open(filename,'wb')
for i in xrange(len(y)):
    f.write(str(y[i])+'\t')
    feature=x[i]
    for (j,k) in enumerate(feature):
        f.write(str(j+1)+':'+str(k)+' ')
    f.write('\n')
f.close() 

if __name__ == "__main__":
    features=targettw()
    print "extracting features for training"
    x_train,y_train=features.allfeat('../data/training/')
    writevec('../data/output/training',x_train,y_train)
    print "extracting features for testing"
    x_test,y_test=features.allfeat('../data/testing/')
    writevec('../data/output/testing',x_test,y_test)

Anyone knows what have I done wrongly? How can I resolve this error? Thanks in advance!

Nana
  • 77
  • 1
  • 11
  • This is a file-permission error. `../data` is probably owned by another user. Running Windows or Linux? – Torxed Mar 13 '16 at 12:40
  • Does the `../data/output/` directory exist, relative to where you're running the script? If you're running it from your home directory, you probably don't own the directory `..` – Simon Fraser Mar 13 '16 at 12:40
  • Does the output folder exist? The code shown doesn't create it. Plus, since it uses .. it could be invalid, depending on the folder you're running the script from. – bluebrother Mar 13 '16 at 12:42
  • @Torxed Running on windows – Nana Mar 13 '16 at 12:47
  • And where exactly would `../data/output/training` be? On a network mount? Could you do (at the top of your script): `import os.path` and `print(os.path.abspath('../data'))` ? – Torxed Mar 13 '16 at 12:49
  • @Torxed hi that returned me this: C:\Users\NANA\Documents\Sentiment Analysis Methods\Target-dependent Twitter Sentiment Classification with Rich Automatic Features\ijcai2015-master\data – Nana Mar 13 '16 at 12:52
  • @SimonFraser Hi, the folder was not inside the file that I downloaded but I have added it in on my own – Nana Mar 13 '16 at 12:53
  • @Nana Your problem is that your folder-name is to long. – Torxed Mar 13 '16 at 12:54

1 Answers1

0

There is a limit in Windows on how long directory/file-names can be in order to open them. Having a too long name will cause weird problems.

If this is the case, here is a good explanation: Why does the 260 character path length limit exist in Windows?

I'd suggest you move your project or the output dir somewhere else, for intsance to r'C:\Users\NANA\Desktop\output' and see if that helps.

This solution comes from comments above and might or might not solve the OP's problem but could be useful for others with similra "odd" issues.

Community
  • 1
  • 1
Torxed
  • 22,866
  • 14
  • 82
  • 131
  • May I clarify, what do you mean by the name is too long in this case? Too many layers or the name itself is too long? – Nana Mar 13 '16 at 13:13
  • @Nana The full path in its text form is to long. Simply counting the characters in the path and adding them up basically. – Torxed Mar 13 '16 at 13:16
  • Would this problem exist if it was linux instead? @Torxed – Nana Mar 13 '16 at 13:22
  • @Nana probably not, but maybe in a different form because there's other permission issues on Linux that you need to take into account. But simply use [absolute paths](http://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python) instead of relative paths (`../` or `./` are all relative to your initial script) and that hsould sove your issue. And also use a different output folder than where you currently try to save your data to. Because the path is probably to long. – Torxed Mar 13 '16 at 13:28