Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in executing the first line of Demo.py #80

Closed
asmileguo opened this issue Sep 13, 2016 · 8 comments
Closed

error in executing the first line of Demo.py #80

asmileguo opened this issue Sep 13, 2016 · 8 comments

Comments

@asmileguo
Copy link

asmileguo commented Sep 13, 2016

Hi,
I am a new comer here. Forgive me if my question sounds stupid.
I run into problem when running the first line of Demo.py (under the folder "ConsumptionSaving")

from ConsIndShockModel import IndShockConsumerType

All that I did was just to enter that folder and execute this first line. The error message is:

File "C:\Users...\Documents\Python\HARK\ConsumptionSaving\ConsIndShockModel.py", line 2242
*raise Exception, "grid_type not recognized in init." + *
^
SyntaxError: invalid syntax

I use Anaconda. Any insight? Thanks.

@dclow
Copy link
Contributor

dclow commented Sep 13, 2016

That's really odd. It seems like it's trying to execute line 2242 of "ConsIndShockModel.py" without also executing line 2243, which is what the + \ at the end is telling it to do

Are you using Spyder? How are you executing Python code? Have you changed any of the files at all?

@asmileguo
Copy link
Author

I found that changing line 2242 into
raise Exception("grid_type not recognized in init." +
"Please ensure grid_type is 'linear' or 'exp_mult'")

solves the problem (at least for the first line error I mentioned).
Was it due to different versions of Python? I run it in Python 3 Jupyter notebook.

@dclow
Copy link
Contributor

dclow commented Sep 13, 2016

Hmmmmm yeah that sounds very possible. HARK is written for and tested in Python 2.7

I'd recommend downloading and installing Python 2.7 if you want to use HARK. If that doesn't fix the problem, please let me know

@asmileguo
Copy link
Author

Thanks David. I'll just check how far it can go with Python 3.

@compumetrika
Copy link
Contributor

I can confirm that the error described above occurs under python 3, but not python 2.

Here is my effort to run the demo with Python 3:

$ cd ~/workspace/HARK/ConsumptionSaving/
$ python3 Demo.py 
Traceback (most recent call last):
  File "Demo.py", line 27, in <module>
    from ConsIndShockModel import IndShockConsumerType
  File "/home/npalmer/workspace/NEW_HARK/ConsumptionSaving/ConsIndShockModel.py", line 2242
    raise Exception, "grid_type not recognized in __init__." + \
                   ^
SyntaxError: invalid syntax

...the same error.

Under Python2.7:

$ python Demo.py 
divide by zero encountered in log
Consumption functions:
MPC out of Credit v MPC out of Income
$

As @dclow noted, HARK has been written for Python 2.7; unfortunately this appears to be one of the places that Python 2/3 differences crop up. Ideally our code would run under both, but as noted above it has only been tested in Python 2.7. There may be more to be said on this.

Thanks for catching this. (Not closing the issue just yet.)

@asmileguo
Copy link
Author

@compumetrika @dclow Thanks for the help. I also confirmed that I could run it on Python 2.7 on my machine without any issues.

@mnwhite
Copy link
Contributor

mnwhite commented Sep 29, 2016

Should we close this issue now, and replace it with one entitled "make HARK compatible with Python 3"?

@mnwhite
Copy link
Contributor

mnwhite commented Jan 9, 2017

Closing because no one has objected to my suggestion for three months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants