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

report if python (not ipython) used for the import #24

Open
ianozsvald opened this issue Nov 3, 2019 · 0 comments
Open

report if python (not ipython) used for the import #24

ianozsvald opened this issue Nov 3, 2019 · 0 comments

Comments

@ianozsvald
Copy link
Owner

ianozsvald commented Nov 3, 2019

Re-raise if the import is done outside of the ipython environment to give the user a clue. With python this lacks the appropriate attributes:

$ python
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipython_memory_usage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ian/workspace/personal_projects/hackathon_ipython_memory_usage/ipython_memory_usage/src/ipython_memory_usage/__init__.py", line 5, in <module>
    import ipython_memory_usage.ipython_memory_usage as imu
  File "/home/ian/workspace/personal_projects/hackathon_ipython_memory_usage/ipython_memory_usage/src/ipython_memory_usage/ipython_memory_usage.py", line 19, in <module>
    input_cells = get_ipython().user_ns['In']
AttributeError: 'NoneType' object has no attribute 'user_ns'

Using IPython is good:

$ ipython
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import ipython_memory_usage                                                                                                                 
In [2]:                                                                 
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

1 participant