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 module named 'thinkstats2' #70

Closed jfulghum closed 2 years ago

jfulghum commented 7 years ago

Hi! When I copy and paste the provided nsfg.py script in Atom or Spyder I get following error:

File "preg.py", line 11, in import thinkstats2 ImportError: No module named 'thinkstats2'

Why is there no module named thinkstats2? Thank you!

AllenDowney commented 7 years ago

If you just copy and paste that script, you won't have the data files or the supporting Python modules. Instructions for working with the code are in the Preface:

http://greenteapress.com/thinkstats2/html/thinkstats2001.html#sec3

Hope that helps.

ashokd79 commented 6 years ago

i am facing the same issue. I have anaconda installed per the instructions, however i am still getting the module not found error for thinkstats2 - ModuleNotFoundError: No module named 'thinkstats2'. can anyone help fixing this issue?

AllenDowney commented 6 years ago

thinkstats2.py is in the ThinkStats2 repository, so if your IDE looks in that directory, you should find it.

The alternative is to

pip install thinkx

The thinkx package contains the files you need for all of the Think books, including thinkstats.py. If you pip install it, it should be on your Python search path.

Hope that helps! Allen

On Sat, Nov 4, 2017 at 6:29 AM, ashokd79 notifications@github.com wrote:

i am facing the same issue. I have anaconda installed per the instructions, however i am still getting the module not found error for thinkstats2 - ModuleNotFoundError: No module named 'thinkstats2'. can anyone help fixing this issue?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-341886629, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37b-IOel8f_1HfBHlvYJmdMPvP4FAks5szDyXgaJpZM4Nh2QS .

ashokd79 commented 6 years ago

Thank you so much, Allen. I tried the pip install thinkx option and it worked. Ii don't get that issue any more, however, i am getting a new issue - I am getting the below file not found error. I checked at the main function, it looks fine, i tried to run everything separately. I dont get any errors but also can't get the code print "All Test Passed" at the end as well. I am stuck and any help or direction will be greatly appreciated.

FileNotFoundError Traceback (most recent call last)

in () 163 164 if __name__ == '__main__': --> 165 main()
AllenDowney commented 6 years ago

This is another version of the same issue. If your IDE is not in the ThinkStats directory, it won't find the data files. You will have to figure out how to get your IDE to look in that directory, or change the code to specify the entire path to the data file.

On Mon, Nov 6, 2017 at 12:33 AM, ashokd79 notifications@github.com wrote:

Thank you so much, Allen. I tried the pip install thinkx option and it worked. Ii don't get that issue any more, however, i am getting a new issue

  • I am getting the below file not found error. I checked at the main function, it looks fine, i tried to run everything separately. I dont get any errors but also can't get the code print "All Test Passed" at the end as well. I am stuck and any help or direction will be greatly appreciated.

FileNotFoundError Traceback (most recent call last) in () 163 164 if name == 'main': --> 165 main()

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-342050765, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37eOaEmUwnrF7nHfuFQmLJzkxQIi0ks5szpohgaJpZM4Nh2QS .

CanoePaddle123 commented 6 years ago

I'm having the same issue. So frustrating, . I find the hard thing with learning python, is not learning, writing code, writing scripts at the start but dealing with these types of issues . Perhaps they go hand in hand. ;

arvindbetrabet commented 6 years ago

This is my experience on a laptop with, Ubuntu 16.04, Anaconda installed, Spyder 3.2.7, Python 3.6.4. Downloaded the ThinkStats2 repository from github as a zip, to an external HD in my case, extracted/un-zipped the file. Using the terminal I "cd"ed to the code folder (after un-zipping the repo from github, the folder structure is the same as on github). Invoked the Spyder IDE, $Spyder at the terminal prompt when it came up navigated to the code directory and opened the nsfg.py and nsfg2.py and clicked on "Run file" the green triangle button. The file ran without any issue, there was a warning 'sys' imported but not used, I commented that line out and ran the file without any errors.

Hope that helps.

BTW, the same process can be used to start the Jupyter $jupyter notebook

This will open a Jupyter UI instance in FireFox and you will see all the ,ipynb files in the code folder

AllenDowney commented 6 years ago

Thanks, that is very helpful. For people who are familiar with the Command Window, that is the way to go.

On Tue, Mar 6, 2018 at 8:00 PM, arvindbetrabet notifications@github.com wrote:

This is my experience on a laptop with, Ubuntu 16.04, Anaconda installed, Spyder 3.2.7, Python 3.6.4. Downloaded the ThinkStats2 repository from github as a zip, to an external HD in my case, extracted/un-zipped the file. Using the terminal I "cd"ed to the code folder (after un-zipping the repo from github, the folder structure is the same as on github). Invoked the Spyder IDE, $Spyder at the terminal prompt when it came up navigated to the code directory and opened the nsfg.py and nsfg2.py and clicked on "Run file" the green triangle button. The file ran without any issue, there was a warning 'sys' imported but not used, I commented that line out and ran the file without any errors.

Hope that helps.

BTW, the same process can be used to start the Jupyter $jupyter notebook

This will open a Jupyter UI instance in FireFox and you will see all the ,ipynb files in the code folder

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-370984992, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37fJqPKnf19s9cflyTQAE6Eobv5gNks5tbzEzgaJpZM4Nh2QS .

CanoePaddle123 commented 6 years ago

Awesome awesome advice. Thanks all

On Mar 6, 2018 8:21 PM, "Allen Downey" notifications@github.com wrote:

Thanks, that is very helpful. For people who are familiar with the Command Window, that is the way to go.

On Tue, Mar 6, 2018 at 8:00 PM, arvindbetrabet notifications@github.com wrote:

This is my experience on a laptop with, Ubuntu 16.04, Anaconda installed, Spyder 3.2.7, Python 3.6.4. Downloaded the ThinkStats2 repository from github as a zip, to an external HD in my case, extracted/un-zipped the file. Using the terminal I "cd"ed to the code folder (after un-zipping the repo from github, the folder structure is the same as on github). Invoked the Spyder IDE, $Spyder at the terminal prompt when it came up navigated to the code directory and opened the nsfg.py and nsfg2.py and clicked on "Run file" the green triangle button. The file ran without any issue, there was a warning 'sys' imported but not used, I commented that line out and ran the file without any errors.

Hope that helps.

BTW, the same process can be used to start the Jupyter $jupyter notebook

This will open a Jupyter UI instance in FireFox and you will see all the ,ipynb files in the code folder

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment- 370984992, or mute the thread https://github.com/notifications/unsubscribe-auth/ ABy37fJqPKnf19s9cflyTQAE6Eobv5gNks5tbzEzgaJpZM4Nh2QS .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-370988912, or mute the thread https://github.com/notifications/unsubscribe-auth/AifPsr02ZbhiFLI-sOuPjyo5TcNNZJnMks5tbzYNgaJpZM4Nh2QS .

RasikaBI commented 6 years ago

@arvindbetrabet , can you please help me its still not working for me. I am using Windows 10. I have all the files in (shared by Allen) in my download folder. I am using jyputer notebook. Not sure how to do it. I tried using command line, copied nfsg and nfsg2.py on Python27 folder and tried running it. Its still not working it gives me the same error again and again : Error 163 164 if name == 'main': --> 165 main()

Please help me

AllenDowney commented 6 years ago

That error is very surprising. What file are you running, how are you running is, and is there an error message?

It seems like you might not be familiar with your software development environment, so starting with Think Stats might not be a good choice.

On Sat, Mar 31, 2018 at 8:09 AM, RasikaBI notifications@github.com wrote:

@arvindbetrabet https://github.com/arvindbetrabet , can you please help me its still not working for me. I am using Windows 10. I have all the files in (shared by Allen) in my download folder. I am using jyputer notebook. Not sure how to do it. I tried using command line, copied nfsg and nfsg2.py on Python27 folder and tried running it. Its still not working it gives me the same error again and again : Error 163 164 if name == 'main': --> 165 main()

Please help me

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-377688561, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37cpjumH16lRHiiVCpp94tE0l5MTtks5tj3HdgaJpZM4Nh2QS .

violet4 commented 6 years ago

in the error you provided, I noticed it says

if name == 'main':

instead of

if __name__ == '__main__':

(I now see it could be a github formatting thing.......... you can make the formatting work properly by adding a line above the code and a line below the code, and on each of those lines place three backticks ("`")). unless python 2 is different from python 3 for that, that looks like a bug (I mostly only use python 3). if you typed that by hand, it's a better idea to copy-paste the whole error message and add the backticks as I mentioned.

I recommend the command line. I don't remember how to open the command line on windows but it should be easy enough to find by google. I think windows uses "chdir" instead of cd (mac and linux use "cd"). "chdir" to "path/to/ThinkStats2/code", where "path/to" should be replaced by the correct path. for example, for me on mac, it's "cd /Users/mica/git/ThinkStats2/code". maybe for you it will be something like "chdir C:\myname\Downloads\ThinkStats2". note that you should have the entire ThinkStats2 repository, not just copying individual files. the files work together, so they all need to be there in the structure that is provided from this repository. the point of chdir'ing/cd'ing to that directory is that python and all the files you're running can find each other properly. if I were to do "cd /Users/mica ; python /Users/mica/git/ThinkStats2/code/nsfg.py" , it would probably fail because nsfg would try to "import somemodule", expecting somemodule to be in the current directory, but it wouldn't find it because it's in /Users/mica/git/ThinkStats2/code/, not in my current directory /Users/mica.

if you are just trying to run nsfg.py and nsfg2.py as recommended by the book, then from that directory just run "python nsfg.py" and then "python nsfg2.py". then when you are ready to work with the jupyter notebooks, run "jupyter notebook" (again it should be from that directory), which by default, should open that directory in the default browser in the jupyter notebook interface. I don't remember how to deal with paths in windows. you might have to type the full path to "jupyter" for it to work, e.g. "C:\path\to\anaconda\bin\jupyter" (with the correct path to anaconda). mine is "/Users/mica/anaconda3/bin/jupyter", but that bin is on my path when I've sourced the anaconda environment so all I have to type is "jupyter notebook".

It seems like you might not be familiar with your software development environment, so starting with Think Stats might not be a good choice.

as Professor Downey mentioned, learning how to do these python things does take some time. I recommend finding one of those books that introduces you to python - usually the first chapter or so will teach a little bit about this stuff.

RasikaBI commented 6 years ago

@mica5 : let me try the suggestions given by you thank you so much

RasikaBI commented 6 years ago

@AllenDowney : Thank you for the reply.i started with Python a month back.. these errors are similar to the errors mentioned above by others. I am unable to run these files on my windows 10.

arvindbetrabet commented 6 years ago

Hi RasikaBI, I have anaconda (https://www.anaconda.com/download/#windows) installed on my Windows 10 laptop, with python version 3.4.4.

I used spyder IDE instead of jupyter notebook (notebooks are mainly used for interactive coding, plotting and creating markdown reports that can be exported as html and sent to folks who want the reports). Please use spyder for learning python (since you mentioned that you are new to python).

When spyder IDE was up and running, I navigated to where I had downloaded the code for the Think Stat book (the code folder) and opened both nsfg.py and nsfg2.py and was able to run both the files.

Hope that helps.

On Sun, Apr 1, 2018 at 11:19 PM, RasikaBI notifications@github.com wrote:

@AllenDowney https://github.com/AllenDowney : Thank you for the reply.i started with Python a month back.. these errors are similar to the errors mentioned above by others. I am unable to run these files on my windows 10.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-377851058, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmkpCDui8Xvb3oDZmFthrEuqXqwonEzks5tkabUgaJpZM4Nh2QS .

chris-kehl commented 6 years ago

This is a small maybe even irrelevant question, but is anyone using the anaconda vscode with these tutorials? I’ve used it to start out with the nsfg.py files seems to work great.

armannp commented 6 years ago

Hi! When I copy and paste the provided nsfg.py script in Atom or Spyder I get following error:

File "preg.py", line 11, in import thinkstats2 ImportError: No module named 'thinkstats2'

Why is there no module named thinkstats2? Thank you!

Hey! I've faced this problem too. The point is that first, you need to download THINKX. For installing packages you will need PIP INSTALL to do it easily. So, first of all, make sure that you have the latest version of pip in your OS. Then, in an environment in which you are working, use this command: pip install thinkx. If you work with Anaconda you should open the terminal in Jupyter then run above command. if you work with python IDE, you should open terminal of your os (in mac).

Finally, you will be able to run nsfg.py... Actually be aware of the location of your data such as this file: dct_file='2002FemResp.dct', You should put the Thinkstats2 file in the right path.

akweteyisaac commented 5 years ago

Hello, I am using pycharm and after adding content root and downloading thinkx I am still getting this

FileNotFoundError: [Errno 2] No such file or directory: '2002FemPreg.dct'

Ajasahib commented 3 years ago

pip install thinkx solved the issue for me. Windows 10 Anaconda jupyter lab

Flash100775 commented 3 years ago

I have Anaconda, Jupyter and Thinkstats2 all installed but when I click on nsfg.py it opens up in a python window not Jupyter. When I try and run it in the python window it opens up python shell but nothing happens. I cut and paste the full programme into Jupyter but again when I run it nothing happens. Can anyone help?

arvindbetrabet commented 3 years ago

nsfg.py, as i understand it is a helper module, so if you read the code it is for reading the data from NSFG - National Survey of Family Growth. It has function definitions for doing that, the only two statements I can see are the print statements that will produce any output, which I am able to replicate when I run the nsfg.py via the command line.

As such Jupyter notebook can only open a file with a .ipynb extension, the .py file can be executed via command line or in an IDE like Spyder.

HTH

On Sun, Feb 28, 2021 at 8:23 AM Flash100775 notifications@github.com wrote:

I have Anaconda, Jupyter and Thinkstats2 all installed but when I click on nsfg.py it opens up in a python window not Jupyter. When I try and run it in the python window it opens up python shell but nothing happens. I cut and paste the full programme into Jupyter but again when I run it nothing happens. Can anyone help?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-787460313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJBULSKZ6SIZ3FSAD5TTBJGU7ANCNFSM4DMHMQJA .

Flash100775 commented 3 years ago

Hi,

Thank you for the information.

I can see the code in IDLE but when I select Run Module a Python Shell window opens but nothing happens and I dont see the output of a print statement. So I am still stuck.

Graham


From: arvindbetrabet notifications@github.com Sent: 28 February 2021 18:11 To: AllenDowney/ThinkStats2 ThinkStats2@noreply.github.com Cc: Flash100775 g_failes@msn.com; Comment comment@noreply.github.com Subject: Re: [AllenDowney/ThinkStats2] No module named 'thinkstats2' (#70)

nsfg.py, as i understand it is a helper module, so if you read the code it is for reading the data from NSFG - National Survey of Family Growth. It has function definitions for doing that, the only two statements I can see are the print statements that will produce any output, which I am able to replicate when I run the nsfg.py via the command line.

As such Jupyter notebook can only open a file with a .ipynb extension, the .py file can be executed via command line or in an IDE like Spyder.

HTH

On Sun, Feb 28, 2021 at 8:23 AM Flash100775 notifications@github.com wrote:

I have Anaconda, Jupyter and Thinkstats2 all installed but when I click on nsfg.py it opens up in a python window not Jupyter. When I try and run it in the python window it opens up python shell but nothing happens. I cut and paste the full programme into Jupyter but again when I run it nothing happens. Can anyone help?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-787460313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJBULSKZ6SIZ3FSAD5TTBJGU7ANCNFSM4DMHMQJA .

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-787495053, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARS6U2ZT7MHF6AZPF5JU4XLTBKBM5ANCNFSM4DMHMQJA.

Flash100775 commented 3 years ago

Hi,

I also cut and pasted the code to Jupyter and when I run it it says it cant find thinkstats2 to import it. I had downloaded thinkstats2 but for some reason the program cannot see it.

Graham


From: Graham Failes g_failes@msn.com Sent: 01 March 2021 16:47 To: AllenDowney/ThinkStats2 reply@reply.github.com Subject: Re: [AllenDowney/ThinkStats2] No module named 'thinkstats2' (#70)

Hi,

Thank you for the information.

I can see the code in IDLE but when I select Run Module a Python Shell window opens but nothing happens and I dont see the output of a print statement. So I am still stuck.

Graham


From: arvindbetrabet notifications@github.com Sent: 28 February 2021 18:11 To: AllenDowney/ThinkStats2 ThinkStats2@noreply.github.com Cc: Flash100775 g_failes@msn.com; Comment comment@noreply.github.com Subject: Re: [AllenDowney/ThinkStats2] No module named 'thinkstats2' (#70)

nsfg.py, as i understand it is a helper module, so if you read the code it is for reading the data from NSFG - National Survey of Family Growth. It has function definitions for doing that, the only two statements I can see are the print statements that will produce any output, which I am able to replicate when I run the nsfg.py via the command line.

As such Jupyter notebook can only open a file with a .ipynb extension, the .py file can be executed via command line or in an IDE like Spyder.

HTH

On Sun, Feb 28, 2021 at 8:23 AM Flash100775 notifications@github.com wrote:

I have Anaconda, Jupyter and Thinkstats2 all installed but when I click on nsfg.py it opens up in a python window not Jupyter. When I try and run it in the python window it opens up python shell but nothing happens. I cut and paste the full programme into Jupyter but again when I run it nothing happens. Can anyone help?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-787460313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJBULSKZ6SIZ3FSAD5TTBJGU7ANCNFSM4DMHMQJA .

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-787495053, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARS6U2ZT7MHF6AZPF5JU4XLTBKBM5ANCNFSM4DMHMQJA.

Flash100775 commented 3 years ago

Still trying. Still stuck...

arvindbetrabet commented 3 years ago

I just downloaded the code from the github site, as a zip file. I unzipped it and ran the nsfg.py as is, no code modification. I am attaching a screen shot of the command window/terminal window(I am running it on a Ubuntu laptop). i have also shown which version of Python I am running. HTH

On Wed, Mar 3, 2021 at 11:49 AM Flash100775 notifications@github.com wrote:

Still trying. Still stuck...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-789931315, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJDML42E6L5IHE23PVTTBZZC3ANCNFSM4DMHMQJA .

Flash100775 commented 3 years ago

Thanks for getting back to me. I could not find the attachment that you mention. When I double click on nsfg.py a window appears for a second then disappears. If I left click and select "open with Python" a window appears then disappears. If I select "open with notebook" I can see the code. If I cut and paste the code to Jupyter and run it I get an error. ModuleNotFoundError: No module named 'thinkstats2'

arvindbetrabet commented 3 years ago

Are you in the US timezone

On Fri, Mar 5, 2021 at 10:47 AM Flash100775 notifications@github.com wrote:

Thanks for getting back to me. I could not find the attachment that you mention. When I double click on nsfg.py a window appears for a second then disappears. If I left click and select "open with Python" a window appears then disappears. If I select "open with notebook" I can see the code. If I cut and paste the code to Jupyter and run it I get an error. ModuleNotFoundError: No module named 'thinkstats2'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-791541889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJGCA2LEQNWEHVZ6YIDTCEDJHANCNFSM4DMHMQJA .

arvindbetrabet commented 3 years ago

[image: Screenshot from 2021-03-03 13-16-13.png]

On Fri, Mar 5, 2021 at 10:47 AM Flash100775 notifications@github.com wrote:

Thanks for getting back to me. I could not find the attachment that you mention. When I double click on nsfg.py a window appears for a second then disappears. If I left click and select "open with Python" a window appears then disappears. If I select "open with notebook" I can see the code. If I cut and paste the code to Jupyter and run it I get an error. ModuleNotFoundError: No module named 'thinkstats2'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-791541889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJGCA2LEQNWEHVZ6YIDTCEDJHANCNFSM4DMHMQJA .

Flash100775 commented 3 years ago

I still cant see the screen shot. All I see is [image: Screenshot from 2021-03-03 13-16-13.png]. I am in Scotland so at London GMT time.

arvindbetrabet commented 3 years ago

I am willing to have a short zoom call, 30 minutes or less, to share my screen and show you, in case you are willing and interested. I am in the US, Central/Chicago time zone.

Please let me know a convenient time for you, as well as which day(s) you prefer. I can send you a zoom meeting invite.

Regards

On Sat, Mar 6, 2021 at 10:29 AM Flash100775 notifications@github.com wrote:

I still cant see the screen shot. All I see is [image: Screenshot from 2021-03-03 13-16-13.png]. I am in Scotland so at London GMT time.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/70#issuecomment-791982617, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2JJFNDSOUFGDJAHUUHBDTCJJ5PANCNFSM4DMHMQJA .

Flash100775 commented 3 years ago

Thanks for the offer of help. Much appreciated. However I think I resolved the problem. I moved the Thinkstats2 downloads into the Anaconda file path and that seems to have worked. I ran the code in IDLE and the tests passed.