AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.03k stars 11.31k forks source link

No such file or directory: '2002FemPreg.dct' #105

Closed NaraMB closed 2 years ago

NaraMB commented 6 years ago

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.

AllenDowney commented 6 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.

NaraMB commented 6 years ago

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:

  1. File > Settings > Project Structure - Here I changed the Content root from /thinkstats2 to /thinkstats2/code and referred to this directory as "Source Folder"
  2. Run > Edit Configurations: Here gave the absolute path to thinkstats2/code folder as the working directory. Could you please tell me which one really worked? (Or else I'll create a similar new project with OOP structure to read some file from some other module and check what worked, but don't want to right now :p. Need to get started with the actual things than researching on an IDE, now)
AllenDowney commented 6 years ago

I am not sure, but I would guess that the second one, setting the working directory, is the one that did the trick.

armannp commented 5 years ago

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.

chetanbawankule commented 4 years ago

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?

wayanlw commented 3 years ago

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}"
        }
    ]
}
heleao commented 3 years ago

Had the same issue

On windows command prompt I was on Documents\Learning\ThinkStats2 I changed directory with "cd code" and it worked

lakshman-luq commented 3 years ago

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".

AllenDowney commented 2 years ago

I'm revising the notebooks so that they download the data files they need. That way people don't have to replicate my environment.

nam42it commented 1 year ago

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

chetanrchetu commented 1 year ago

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