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

quantecon.models.__init__.py problem #123

Closed
davidrpugh opened this issue Feb 13, 2015 · 32 comments
Closed

quantecon.models.__init__.py problem #123

davidrpugh opened this issue Feb 13, 2015 · 32 comments

Comments

@davidrpugh
Copy link
Contributor

@jstac

I report your initial error for reference...

In [1]: import quantecon
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ca57accf01d0> in <module>()
----> 1 import quantecon

/home/john/anaconda/lib/python2.7/site-packages/quantecon/__init__.py
in <module>()
      3 """
      4
----> 5 from . import models as models
      6 from .compute_fp import compute_fixed_point
      7 from .cartesian import cartesian, mlinspace

/home/john/anaconda/lib/python2.7/site-packages/quantecon/models/__init__.py
in <module>()
     10            "solow"]
     11
---> 12 from . import solow as solow
     13 from .asset_pricing import AssetPrices
     14 from .career import CareerWorkerProblem

ImportError: cannot import name solow

Now here is what I have done to try and replicate your error message. I created a completely new conda environment using...

$ conda create -n quantecon-test anaconda
$ source activate quantecon-test

...then changed into my local clone of quant-econ and run...

pip install -e .

... which installs quantecon from my local repo in editable mode (i.e., for dev work).

Now I check the contents of the offending __init__.py script...

"""
models directory imports

objects imported here will live in the `quantecon.models` namespace

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

from . import solow as solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel

I then change back to my root, head into ipython and am able to import quantecon and access the solow module without issue...

(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: from quantecon.models import solow

In [3]: solow.
solow.CESModel          solow.ces               solow.model
solow.CobbDouglasModel  solow.cobb_douglas      
solow.Model             solow.impulse_response  

In [3]: solow.

...I can't replicate your issue on my machine. I did get your email saying that @cc7768 had been able to replicate the issue. I am a bit bamboozled...

@davidrpugh
Copy link
Contributor Author

@jstac

I went and had a look at the __init__.py files for NumPy. Based on what I see there, it would seem that my previous fix should have worked as well.

When I changed models.__init__.py to read...

"""
models directory imports

objects imported here will live in the `quantecon.models` namespace

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

from . import solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel

I can change back to my root directory, head into ipython and can still import quantecon as expected...

(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.career
qe.models.CareerWorkerProblem  qe.models.ifp
qe.models.ConsumerProblem      qe.models.jv
qe.models.GrowthModel          qe.models.lucastree
qe.models.JvWorker             qe.models.odu
qe.models.LucasTree            qe.models.optgrowth
qe.models.SearchProblem        qe.models.solow
qe.models.asset_pricing        

In [2]: qe.models.solow.
qe.models.solow.CESModel          qe.models.solow.cobb_douglas
qe.models.solow.CobbDouglasModel  qe.models.solow.impulse_response
qe.models.solow.Model             qe.models.solow.model
qe.models.solow.ces               

I am really confused now as two fixes that I expected to work (and did work on my machine) have now failed to work for others...

@davidrpugh
Copy link
Contributor Author

@spencerlyon2 and @albop

Can either (or both) check to see whether you can import quantecon and assuming that you can, try to import the solow module using

from quantecon.models import solow

@sglyon
Copy link
Member

sglyon commented Feb 13, 2015

Doesn't work for me:

In [1]: from quantecon.models import solow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-13c41ca4a313> in <module>()
----> 1 from quantecon.models import solow

ImportError: cannot import name solow

@davidrpugh
Copy link
Contributor Author

@spencerlyon2

Damn. This is bizarre. Did you install a fresh conda environment as described above?

@sglyon
Copy link
Member

sglyon commented Feb 13, 2015

Strange. I did not install a fresh conda environment last time. However, when I do install a fresh one everything works. Perhaps the cache of some previous installation is not getting cleaned when I installed into my existing env.

@davidrpugh
Copy link
Contributor Author

Phew. Serious self-doubt was starting to creep in for a bit! Just to be sure I did another fresh conda environment where I built quantecon using a brand new clone (i.e., not my "normal" local repo).

I then changed the quantecon.models.__init__.py file to read:

"""
models directory imports

objects imported here will live in the `quantecon.models` namespace

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

from . import solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel

and everything worked fine:

(quantecon-test)Davids-MacBook-Pro:~ drpugh$ cd Downloads/QuantEcon.py/quantecon/models/
(quantecon-test)Davids-MacBook-Pro:models drpugh$ nano __init__.py
(quantecon-test)Davids-MacBook-Pro:models drpugh$ cd
(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.career
qe.models.CareerWorkerProblem  qe.models.ifp
qe.models.ConsumerProblem      qe.models.jv
qe.models.GrowthModel          qe.models.lucastree
qe.models.JvWorker             qe.models.odu
qe.models.LucasTree            qe.models.optgrowth
qe.models.SearchProblem        qe.models.solow
qe.models.asset_pricing        

In [2]: qe.models.solow.
qe.models.solow.CESModel          qe.models.solow.cobb_douglas
qe.models.solow.CobbDouglasModel  qe.models.solow.impulse_response
qe.models.solow.Model             qe.models.solow.model
qe.models.solow.ces               

In [2]: qe.models.solow.

Perhaps @jstac an/or @cc7768 could create a fresh conda environment and see if that fixed the problem for them as well.

@davidrpugh
Copy link
Contributor Author

@spencerlyon2

If creating a fresh conda environment fixes the problem, this raises another issue: which is why is the cached not clearing properly in your dev environments? Did you build your dev environment using the script on the Wiki?

I am suspicious about step 5, I was taught (by IPython devs at SciPy 2014) that the magic incantation to install a package in "dev-mode" is to run

pip install -e .

from within the directory containing setup.py (after activating your conda environment of course).

@cc7768
Copy link
Member

cc7768 commented Feb 13, 2015

I created a fresh conda environment and run into the same problem. @jstac did it work for you?

@davidrpugh
Copy link
Contributor Author

@cc7768

Did you create a fresh conda environment using the steps that I outlined above? In particular did you use the

pip install -e .

command? Or did you use the instructions on the Wiki?

@cc7768
Copy link
Member

cc7768 commented Feb 13, 2015

I did it both ways and didn't work earlier, but the issue was that I hadn't pulled though (I tried on a different computer yesterday). After pulling (and uncommenting the solow import) it seems to be working for me. Don't know what has changed.

@jstac
Copy link
Contributor

jstac commented Feb 14, 2015

Still not working from me on either of my two machines:

After uncommenting the line

from . import solow as solow

in models.__init__.py and setting the pwd to my root dir I get

In [1]: import quantecon
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ca57accf01d0> in <module>()
----> 1 import quantecon

/home/john/anaconda/lib/python2.7/site-packages/quantecon/__init__.py in <module>()
      3 """
      4 
----> 5 from . import models as models
      6 from .compute_fp import compute_fixed_point
      7 from .cartesian import cartesian, mlinspace

/home/john/anaconda/lib/python2.7/site-packages/quantecon/models/__init__.py in <module>()
     10            "solow"]
     11 
---> 12 from . import solow as solow
     13 from .asset_pricing import AssetPrices
     14 from .career import CareerWorkerProblem

ImportError: cannot import name solow

Very weird. I don't have any ideas. I'll test it in a fresh environ but in a way the result is moot -- we have to leave those imports out until it's stable in all settings.

@jstac
Copy link
Contributor

jstac commented Feb 14, 2015

Creating a fresh conda environment, uncommenting from . import solow as solow and installing via python setup.py install leads to the same error on my machine.

@davidrpugh
Copy link
Contributor Author

@jstac

Can you please try creating a new conda environment using the commands that I suggest above specifically the commands

$ conda create -n quantecon-test anaconda
$ source activate quantecon-test

Then cd into local clone of the repo and run

$ pip install -e .

This is how I was taught to create dev-environment by IPython devs (which is different than instructions currently on the QuantEcon Wiki). I am trying to isolate whether the issue is the difference in the way that we initially created dev environments.

@davidrpugh
Copy link
Contributor Author

@spencerlyon2 @cc7768 @jstac

Another thought that I had is that import statements on your machines might have been using old __init__.pyc file in quantecon.models. These files are not under version control. This means that, while the __init__.py file itself has changed to include solow, you might still be using a cached version of the old file (which doesn't) when the import statements are actually executed.

To test this hypothesis, I suppose that you could delete all of the *.pyc files (or possible just quantecon/models.__init__.pyc).

@jstac
Copy link
Contributor

jstac commented Feb 14, 2015

Hi all, installation works and all imports are successful after running

pip install -e QuantEcon.py

This is a really weird and frustrating bug. We can change the wiki to encourage people to install this way but even so python setup.py install is so common that I'm sure many people will use it. I definitely don't want to introduce this kind of instability into the package.

At present @mmcky is off line but he will be back in a day or two. I would like to get his thoughts on this.

@davidrpugh
Copy link
Contributor Author

@jstac

I don't think this is a bug in the code. The bug is in the way that the development environments have been set up for anyone who set them up using the instructions on the Wiki. The command

python setup.py install

is not the correct command to use if you want to install a package in "develop" mode. See, for example, this SO post for details. To install in develop mode you should use either

python setup.py develop

or

pip install -e QuantEcon.py

or some other equivalent.

@cc7768
Copy link
Member

cc7768 commented Feb 15, 2015

@davidrpugh @jstac I can't figure out what exactly is going on with why these imports are failing. Got some feedback from some other students that they aren't able to import quantecon. It seems to be an ongoing issue.

I think we can agree that ultimately we want others to be able to install and import the quantecon package by simply typing python setup.py install without hiccups. python setup.py develop seems to simply add capability of letting files change and knowing where to look which relatively few of our users will be making changes within the code and we don't want a complicated install process.

Those things being said, I'm not sure that it is the __init__.py files that are the issue in them though because if we are able to do it at all then that hints to me that there is a different (and possibly deeper) problem at fault. We should pin down what exactly that is. Is it the caching like @davidrpugh mentioned earlier? At the same time, this system has been pretty well tested and I would be surprised if there was a bug... I'm not sure what it is I guess

@jstac
Copy link
Contributor

jstac commented Feb 15, 2015

@davidrpugh Sure, I understand that this isn't a bug in the code per se --- or at least I very much doubt it is. And now we have some information from @cc7768 that it might be an ongoing issue.

I strongly agree with @cc7768 that we want people to be able to install with python setup.py install or any other reasonable method of their choice (conditional on having installed Anaconda). After all, not everyone is going to read our Wiki or instructions, and nor should they have to --- it should just work.

I've asked @mmcky to look into this. Perhaps some fresh eyes will help.

@davidrpugh
Copy link
Contributor Author

All,

I am worried that we are conflating installation by users and installation by developers: these are two separate processes.

  1. I completely agree that we want users of the library, who have no intention of making changes to the source code, to be able to install quantecon using python setup.py install after downloading source from GitHub. Obviously it would be much easier to install using pip install quantecon as recommended on the website). Regardless, as @jstac says either method should "just work." @cc7768 seems to indicate that there might be examples of this not working. Is this correct?
  2. However, users of the library who do plan on contributing to the development of quantecon should not install using python setup.py install but should install using either pip install -e QuantEcon.py or python setup.py develop after cloning source locally from GitHub. Not setting up the development environment correctly will mean that development changes made to source code will not be cached properly. This is likely to cause subtle "bugs."

Does anyone disagree with either of these points?

I think that failure to set up the development environment so that changes to source files are correctly cached is the source of our present difficulty. As best as I can tell from this thread, everyone that had trouble importing the package was developing a quantecon library that had been installed using python setup.py install; once they moved to a new development environment in which quantecon had been installed using either python setup.py develop or pip install -e . or pip install -e QuantEcon.py, then the issue disappeared.

Do we have counter-examples to this hypothesis?

@davidrpugh
Copy link
Contributor Author

All,

I realized that I hadn't been terribly specific about the important distinction between the commands

python setup.py install

and the commands

python setup.py develop
pip install -e .

so here goes.

When you install quantecon (or any package) using python setup.py install from inside the project source, this will install quantecon into the standard location (typically the site-packages directory). If you then cd into the source directory and start making changes, these changes will be immediately available for import BUT only as long as you remain within the same directory as the files that have been changed. This is because (I think) the current working directory gets appended to the import path automatically which means the current working directory will take precedence over the standard install location. If however, you cd out of the source folder with your changes, say to root, and then try to import quantecon, any changes made to source will not be available because these changes have not been propagated to the quantecon package that was installed in site-packages.

Now if you install quantecon (or any package) using python setup.py develop or pip install -e . from inside the project source, this will install quantecon AND link the quantecon source code and the installed quantecon package so that changes to quantecon source made during development are immediately propagated to the installed quantecon library and thus available for import anywhere on the system.

Does this make sense?

@davidrpugh
Copy link
Contributor Author

@jstac

So far as I can tell, the Travis CI builds are all passing without issue. If this is true, then this would be another indication that the problem is likely with the way development environments are being set up and not with the code base itself.

@jstac
Copy link
Contributor

jstac commented Feb 15, 2015

@davidrpugh Thanks for additional comments. They were useful for me.

My priority is that the package is stable across all standard environments and all standard installation methods.

@cc7768
Copy link
Member

cc7768 commented Feb 15, 2015

I personally see little difference in installation by developers and installation by users. Ultimately, developers are also users, and I still feel that python setup.py install should just work for anybody at any time. I am aware of the differences between "develop" and "install" and it doesn't change what I think about this. If I want to develop in a slightly slower way where I go back to the directory and type python setup.py install for each change I make then that should work.

  1. Yes there are examples of it not "just working" for some students here that have emailed me asking me to help (current solution I gave everyone was for everyone to comment out the line a la what we have on master right now). To recreate, I just installed the anaconda python distribution (completely fresh install) on my wife's computer and cloned into QuantEcon.py (uncommented the from . import solow line) and tried to install. I am getting the import error outside of the QuantEcon.py directory and not getting the import error from within the QuantEcon.py directory
  2. I am not sure that not using python setup.py develop or pip install -e should cause caching issues? Do you have a link that discusses this (I have read all links posted so far and found no discussion of this)? From what I understand, using develop or -e basically links the quantecon folder so that updates are made in real time.

I think this is interesting code and we should figure out how to get it seamlessly incorporated. I think there is something going wrong right now and we need to pin down what exactly it is. I'm starting to suspect that the issue lies in the problem with it working inside the QuantEcon.py directory and not working from outside. I think (and this is where my understanding of what develop and -e gets a little hazy so correct me if I'm wrong) develop and -e both link the folder to the .egg (I think) so that you essentially are working from within the folder. I think if we pin down why this isn't working then we will pin down what the issue is . This might also explain why Travis is succeeding -- It might be testing from folder (once again this is speculation because I don't know exactly where Travis runs the tests from etc...)

@davidrpugh What happens if you don't install with pip install -e or python setup.py develop? Can you uninstall and try installing with python setup.py install? Does it work outside the directory for you?

@mmcky
Copy link
Contributor

mmcky commented Feb 16, 2015

Hi All. I have had a look at the repo and I have a few comments below.

  1. I think one thing perhaps causing a bit of confusion in this thread is the use of python or ipython within the QuantEcon.py folder. This will always work because python will traverse the local folder hierarchy (using __init__.py files for valid packages etc.) and is always used in preference of the site-packages installation packages. To use the installed version make sure you are working outside of your local quantecon folder.

I think there are also a few errors in the way the package is currently setup for distribution using distutils - which is why pip install / upgrade isn't working properly.

  1. the quantecon.models.solow needs to be added to setup.py so that distutils knows that the models.solow sub-sub-package is to be included in the pypi distribution and/or installation using python setup.py install. (Commit: 4ec8120).
  2. the versions file writer was not working properly and so the version attribute wasn't updating. (Commit: a600036)

@davidrpugh @cc7768 @jstac @spencerlyon2 Could someone please pull the latest and see if this resolves their issues?

Side Comments:

You can check version by using the version attribute

In [1]: import quantecon as qe

In [2]: qe.__version__
Out[2]: '0.1.7-2'

Also one easy way to check which source package you have imported is to enter the module in ipython which returns the path

In [3]: qe
Out[3]: <module 'quantecon' from '/home/matthewmckay/anaconda/lib/python2.7/site-packages/quantecon/__init__.pyc'>

versus this when you are in the quantecon folder

In [2]: qe
Out[2]: <module 'quantecon' from 'quantecon/__init__.pyc'>

@jstac
Copy link
Contributor

jstac commented Feb 16, 2015

@mmcky Great work.

Everything now working on both my machines. How about everyone else?

@davidrpugh
Copy link
Contributor Author

@jstac

How did you install? Using python setup.py install or one of the commands like pip install -e . for installing in develop mode? It would be useful to know in order to separately identify the impact of @mmcky commits from the way in which the environment is setup.

@davidrpugh
Copy link
Contributor Author

@cc7768

The error you describe in 1 is exactly what I would have expected you to get if you installed quantecon using python setup.py install, then made changes to the source, and then tried to access those changes from outside the QuantEcon.py directory. Inside the directory everything should work fine and did. If you then re-ran python setup.py install after making changes, the changes would then get installed, and then everything should work fine even outside of the QuantEcon.py directory.

Developing in this way seems terribly inefficient but would work. Seems much easier to just use one of the commands above to install in develop mode.

@davidrpugh
Copy link
Contributor Author

@jstac @cc7768 @spencerlyon2 @mmcky

I continue to get the same behavior after pulling the new commits from @mmcky as I was previously (which is good because everything was working correctly on my machine to begin with).

For completeness I performed two experiments the results of which I report below...

Experiment 1: Using instructions on the Wiki...

I tried the following commands...

$ conda create -n quantecon-test anaconda
$ source activate quantecon-test
$ cd Downloads/QuantEcon.py/
$ python setup.py install

...and then checked the contents of quantecon/models/__init__.py

"""
models directory imports

objects imported here will live in the `quantecon.models` namespace

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

#from . import solow as solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"__init__.py" 19L, 527C

Note that import statement is commented out.

I now head into IPython from root

(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.asset_pricing
qe.models.CareerWorkerProblem  qe.models.career
qe.models.ConsumerProblem      qe.models.ifp
qe.models.GrowthModel          qe.models.jv
qe.models.JvWorker             qe.models.lucastree
qe.models.LucasTree            qe.models.odu
qe.models.SearchProblem        qe.models.optgrowth

In [2]: qe.models.solow
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-3c88fd58e5e4> in <module>()
----> 1 qe.models.solow

AttributeError: 'module' object has no attribute 'solow'

In [3]: from quantecon.models import solow

In [4]: solow.
solow.CESModel          solow.ces               solow.model
solow.CobbDouglasModel  solow.cobb_douglas      
solow.Model             solow.impulse_response  

In [4]: solow.

I expected to see the AttributeError given that the from . import solow is commented out in the __init__.py file above. This statement from quantecon.models import solow was broken on QuantEcon installed from pypi and was what started off this whole thread (I assume that this has been fixed by the recent commits by @mmcky).

Now I uncomment the import statement in quantecon/models/__init__.py

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

from . import solow as solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"__init__.py" 19L, 527C

and now I again head into IPython from root

(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.asset_pricing
qe.models.CareerWorkerProblem  qe.models.career
qe.models.ConsumerProblem      qe.models.ifp
qe.models.GrowthModel          qe.models.jv
qe.models.JvWorker             qe.models.lucastree
qe.models.LucasTree            qe.models.odu
qe.models.SearchProblem        qe.models.optgrowth

In [2]: qe.models.solow
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-3c88fd58e5e4> in <module>()
----> 1 qe.models.solow

AttributeError: 'module' object has no attribute 'solow'

In [3]: from quantecon.models import solow

In [4]: solow.
solow.CESModel          solow.ces               solow.model
solow.CobbDouglasModel  solow.cobb_douglas      
solow.Model             solow.impulse_response  

In [4]: solow.

As expected I get the same results, the changes made to models/__init__.py have not been propagated to the installed version of the package.

Now if I go back into QuantEcon.py and re-install using python setup.py install the changes made to models/__init__.py are propagated and I can find the solow package as desired.

(quantecon-test)Davids-MacBook-Pro:QuantEcon.py drpugh$ cd
(quantecon-test)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.career
qe.models.CareerWorkerProblem  qe.models.ifp
qe.models.ConsumerProblem      qe.models.jv
qe.models.GrowthModel          qe.models.lucastree
qe.models.JvWorker             qe.models.odu
qe.models.LucasTree            qe.models.optgrowth
qe.models.SearchProblem        qe.models.solow
qe.models.asset_pricing        

In [2]: qe.models.solow.
qe.models.solow.CESModel          qe.models.solow.cobb_douglas
qe.models.solow.CobbDouglasModel  qe.models.solow.impulse_response
qe.models.solow.Model             qe.models.solow.model
qe.models.solow.ces               

In [2]: qe.models.solow.

Experiment 2: Installing in 'dev' mode

I tried the following commands...

$ conda create -n quantecon-test2 anaconda
$ source activate quantecon-test
$ cd Downloads/QuantEcon.py/
$ pip install -e .

...and then checked the contents of quantecon/models/__init__.py

"""
models directory imports

objects imported here will live in the `quantecon.models` namespace

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

#from . import solow as solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"__init__.py" 19L, 527C

again note that the import statement is commented out.

Now head to root and enter IPython

(quantecon-test2)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.asset_pricing
qe.models.CareerWorkerProblem  qe.models.career
qe.models.ConsumerProblem      qe.models.ifp
qe.models.GrowthModel          qe.models.jv
qe.models.JvWorker             qe.models.lucastree
qe.models.LucasTree            qe.models.odu
qe.models.SearchProblem        qe.models.optgrowth

In [2]: qe.models.solow
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-3c88fd58e5e4> in <module>()
----> 1 qe.models.solow

AttributeError: 'module' object has no attribute 'solow'

In [3]: 

Same behavior as Experiment 1 with the import statement commented out in the __init__.py file.

Now I make changes to quantecon/models/__init__.py...

"""

__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
           "JvWorker", "LucasTree", "SearchProblem", "GrowthModel",
           "solow"]

from . import solow as solow
from .asset_pricing import AssetPrices
from .career import CareerWorkerProblem
from .ifp import ConsumerProblem
from .jv import JvWorker
from .lucastree import LucasTree
from .odu import SearchProblem
from .optgrowth import GrowthModel
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"__init__.py" 19L, 527C

and now I again head into IPython from root

(quantecon-test2)Davids-MacBook-Pro:~ drpugh$ ipython
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import quantecon as qe

In [2]: qe.models.
qe.models.AssetPrices          qe.models.career
qe.models.CareerWorkerProblem  qe.models.ifp
qe.models.ConsumerProblem      qe.models.jv
qe.models.GrowthModel          qe.models.lucastree
qe.models.JvWorker             qe.models.odu
qe.models.LucasTree            qe.models.optgrowth
qe.models.SearchProblem        qe.models.solow
qe.models.asset_pricing        

In [2]: qe.models.solow.
qe.models.solow.CESModel          qe.models.solow.cobb_douglas
qe.models.solow.CobbDouglasModel  qe.models.solow.impulse_response
qe.models.solow.Model             qe.models.solow.model
qe.models.solow.ces               

In [2]: qe.models.solow.

and as expected given that I had installed quantecon in development mode using pip install -e . command the changes made to the models/__init__.py file were immediately propagated.

Hope everyone finds this useful...

@cc7768
Copy link
Member

cc7768 commented Feb 16, 2015

@davidrpugh Agree that it is slightly inefficient -- Mostly just making the point that it should work. It looks like we were all just looking in wrong place. Excited that we are good to go with this code (all of my machines are good now) and I learned a little more about what needs to change when introducing new sub-packages.

@jstac
Copy link
Contributor

jstac commented Feb 16, 2015

@davidrpugh I installed via python setup.py install since the other approach was already working.

I guess we're done here. Thanks everyone for input and thanks again to @mmcky for clearing this up.

@davidrpugh
Copy link
Contributor Author

Glad that it is up an running for everyone now. Should I go ahead and close the issue?

@jstac
Copy link
Contributor

jstac commented Feb 16, 2015

Closing now.

@jstac jstac closed this as completed Feb 16, 2015
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

5 participants