ipython_memory_usage icon indicating copy to clipboard operation
ipython_memory_usage copied to clipboard

report if python (not ipython) used for the import

Open ianozsvald opened this issue 5 years ago • 0 comments

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

ianozsvald avatar Nov 03 '19 11:11 ianozsvald