Closed NaraMB closed 2 years ago
When you run a program, it runs in an environment that includes the "current directory", which is where it looks for things like this data file. If you explore your IDE, you should find a place where you can specify the current directory.
Alternatively, you can modify the program to specify the complete path to the data file.
Ahhh, thanks Allen. It worked at last. I wasn't really interested in using absolute path name. I did two changes after going through some stackoverflow and Pycharm documentation. I'm really not sure what really worked. Two changes, I did:
I am not sure, but I would guess that the second one, setting the working directory, is the one that did the trick.
Hi, I had the same problem. I use the notebook, I faced this error: IDE is not able to recognize the file '2002FemPreg.dct'. I copied the whole code file in the directory which untitled.ipynb was located.
I am using jupyter notebook , while running nsfg.py i am getting "[Errno 2] No such file or directory: '2002FemResp.dct'" this error, What should i do?
Had the same issue, while I was using VS code. The solution was to add the line "cwd": "${fileDirname}"
to the launch.json as follows
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}"
}
]
}
Had the same issue
On windows command prompt I was on Documents\Learning\ThinkStats2 I changed directory with "cd code" and it worked
I had the same issue in VS code and I figured it out. Just open folder ThinkStats2/code in your VS code and run file "nsfg.py" If you don't see any import errors you'll see a print message like "All tests passed".
I'm revising the notebooks so that they download the data files they need. That way people don't have to replicate my environment.
You can download the data file with name 2002Male.date ... You Copy and Paste it in the Folder name ThinkStats.code or anywhere you put your code and run Hope you can reslove it Love
the solution to the error is in the nsfg.py def ReadFemResp(dct_file=here give the complete path of 2002FemResp.dct, dat_file=here give the complete path of 2002FemResp.dat.gz', nrows=None):
example: def ReadFemResp(dct_file='D:\think stats\ThinkStats2\code\2002FemResp.dct', dat_file='D:\think stats\ThinkStats2\code\2002FemResp.dat.gz', nrows=None):
and in def ReadFemPreg(dct_file=here give the complete path of 2002FemPreg.dct', dat_file=here give the complete path of 2002FemPreg.dat.gz'): example: def ReadFemPreg(dct_file='D:\think stats\ThinkStats2\code\2002FemPreg.dct', dat_file='D:\think stats\ThinkStats2\code\2002FemPreg.dat.gz'):
this will surly work and in thinkstats2.py comment the assert lines
this willl surely work
I have cloned the git directory to some place in my computer and I am opening the project with the pycharm IDE. I can run nsfg.py from pycharm and see the output. When, I go to chap01ex.ipynb, i got this module error: no module named nsfg. I installed thinkx using pip and that issue got resolved. But when I run nsfg.ReadFemPreg(), I see that IDE is not able to recognize the file '2002FemPreg.dct'. I have added the project path to PYTHONPATH in the environment variables as well. I do not see any solution working for me. Please help me on this. Eagerly, waiting to get started.