Skip to content

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

Description

@ianozsvald

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]:                                                                 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions