0

I've been having a lot of trouble importing a package in Python called "scanpy" - I've been trying to follow this tutorial here (https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html) but Python seems to view "scanpy" as a module of a package rather than a packge itself:

import numpy as np
import pandas as pd
import scanpy as sc
sc.settings.verbosity = 3
sc.logging.print_header()
sc.settings.set_figure_params(dpi=80, facecolor='white')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-129af3139565> in <module>
----> 1 sc.settings.verbosity = 3
      2 sc.logging.print_header()
      3 sc.settings.set_figure_params(dpi=80, facecolor='white')

AttributeError: module 'scanpy' has no attribute 'settings'

Other people seem to have also had trouble installing "scanpy," so I followed kleurless's installation instructions on this GitHub thread (https://github.com/theislab/scanpy/issues/990). This is the result of those installation instructions. (Separately, I've also followed the installation instructions on the "scanpy" website but those didn't seem to work.) I'm also running the above lines of code in a Jupyter Notebook if that matters. I forgot to load the virtual environment before I loaded the Jupyter Notebook so I included "!source activate scanpy_environment" before the first line but that didn't help. If someone could help me, I would be extremely grateful.

Aaron
  • 113
  • 1
  • 7
  • packages *are modules*, which contain *submodules*. That is it. – juanpa.arrivillaga Dec 24 '21 at 03:48
  • Anyway, what version of `scanpy` are you using? This may be related: https://github.com/theislab/scanpy-tutorials/issues/1 – juanpa.arrivillaga Dec 24 '21 at 03:49
  • 1
    By any chance, is there a file called `scanpy.py` in your working directory? i.e. if you do `!ls` in your jupyter notebook? – juanpa.arrivillaga Dec 24 '21 at 03:51
  • 1
    Thanks for your comments @juanpa.arrivillaga, I'm not quite sure what version of "scanpy" it is - I tried "sc.__version__" but that didn't return anything. I also tried "!conda list" but "scanpy" didn't appear there, so I'm not quite sure if my virtual environment activated properly – Aaron Dec 24 '21 at 03:53
  • 1
    Standard debugging for problems like this: `print(sc.__file__)` to see exactly where the module is coming from, `print(dir(sc))` to see what's actually in it. – jasonharper Dec 24 '21 at 03:54
  • @juanpa.arrivillaga I don't see "scanpy.py" unfortunately – Aaron Dec 24 '21 at 03:54
  • Thanks for your comment @jasonharper, I tried "print(sc.__file__)" but that returned "None" - I also tried "print(dir(sc))" and that returned "['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']" – Aaron Dec 24 '21 at 03:55
  • @jasonharper based on "print(dir(sc))," do you think "scanpy" has been properly imported? – Aaron Dec 24 '21 at 03:57
  • Open a plain Python shell (not jupyter inside the browser) in a different directory, rerun and test it. If it still fails, give us the debugging information above. – smci Dec 24 '21 at 05:08

1 Answers1

0

I just installed this on my backup test ubuntu computer and it works. enter image description here

I did: pip install scanpy in the bash terminal then once it was installed I wrote this test script and ran it:

import scanpy as sc

sc.settings.verbosity = 3
sc.logging.print_header()
sc.settings.set_figure_params(dpi=80, facecolor='white')

print(sc.settings.verbosity)
print("test")

If it works, then it could be an issue with Jupyter notebook.

I would also say to check your modules by using pip freeze to see if scanpy is installed.