pythonanacondacanopygenfromtxt

Difference in genfromtxt between Anaconda and Canopy


i am using Anaconda (spyder IDE) to program in Python, but I recently installed Canopy. In most of my programs I'm using genfromtxt command to load data into my programs. The whole line looks like this

data=np.genfromtxt('Data/1.txt',usecols=(0,1),delimiter='\t')

In Anaconda this works fine, but when I try to run the same code in Canopy I get the following error

OSError: Data/1.txt not found.

Could, having the both distributions installed at the same time, be the problem? Or does Canopy requires different syntax for writing filepath? I know this is basic problem, but I don't know what to do with this at all. Also I'm using Mac OS High Sierra. Maybe it is important.

Thanks


Solution

  • The problem is that you are running the script in a directory different than the code expects. It's generally best practice for your code not to assume that your data is in your script directory, but for a quick solution, it will suffice to change your cwd in the Canopy editor. See "Change directory" in the Canopy docs.

    Could, having the both distributions installed at the same time, be the problem?

    No, it is not the source of this problem. However, tangentially, when you have multiple python environments installed (even, e.g. if they are multiple conda or canopy / edm environments), then none of them should be on your PATH by default to avoid confusion. To run Canopy, none of them need to be on your PATH.