question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scanpy/api/pl.py "cannot import name stacked_violin" from 'scanpy.plotting._anndata'

See original GitHub issue
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.

Minimal code sample (that we can copy&paste without having any data)

import scanpy.api as sc
  File "./scanpy_normalization.py", line 4, in <module>
    import scanpy.api as sc
  File "/usr/local/lib/python3.8/site-packages/scanpy/api/__init__.py", line 27, in <module>
    from . import pl
  File "/usr/local/lib/python3.8/site-packages/scanpy/api/pl.py", line 1, in <module>
    from ..plotting._anndata import scatter, violin, ranking, clustermap, stacked_violin, heatmap, dotplot, matrixplot, tracksplot
ImportError: cannot import name 'stacked_violin' from 'scanpy.plotting._anndata' (/usr/local/lib/python3.8/site-packages/scanpy/plotting/_anndata.py)

This is with the latest version of scanpy. I looked at the code and scanpy/apt/pl.py still has from …plotting._anndata import scatter, violin, ranking, clustermap, stacked_violin, heatmap, dotplot, matrixplot, tracksplot, even as the plotting library has been refactored and the dotplot, matrixplot and stacked_violin are now in separate files.

I tested this a few days ago and it was working fine then, the update to anndata probably happened in the last couple of days

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
WeimiaoWucommented, Sep 1, 2020

I’m actually testing and tweaking someone else’s code that was written a while ago. I assume they used import scanpy.api as sc because it was appropriate then. I personally resolved my issue by downgrading versions, I just wanted to bring this up!

I encountered the same issue. Which version are you using to fix this?

nm, downgrading to 1.5.1 fixed my problem. Thanks!

0reactions
detroutcommented, Jan 21, 2021

Hi I had this problem as well with 1.6.0 it was triggered by scanpy’s test code.

scanpy.api (unittest.loader._FailedTest) ... ERROR

======================================================================
ERROR: scanpy.api (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: scanpy.api
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.9_scanpy/build/scanpy/api/__init__.py", line 27, in <module>
    from . import pl
  File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.9_scanpy/build/scanpy/api/pl.py", line 1, in <module>
    from ..plotting._anndata import scatter, violin, ranking, clustermap, stacked_violin, heatmap, dotplot, matrixplot, tracksplot
ImportError: cannot import name 'stacked_violin' from 'scanpy.plotting._anndata' (/<<PKGBUILDDIR>>/.pybuild/cpython3_3.9_scanpy/build/scanpy/plotting/_anndata.py)


----------------------------------------------------------------------
Ran 1 test in 0.000s

I ended up with this patch to get the tests to run successfully.

--- a/scanpy/api/pl.py
+++ b/scanpy/api/pl.py
@@ -1,4 +1,7 @@
-from ..plotting._anndata import scatter, violin, ranking, clustermap, stacked_violin, heatmap, dotplot, matrixplot, tracksplot
+from ..plotting._anndata import scatter, violin, ranking, clustermap, heatmap, tracksplot
+from ..plotting._stacked_violin import stacked_violin
+from ..plotting._dotplot import dotplot
+from ..plotting._matrixplot import matrixplot
 
 from ..plotting._preprocessing import filter_genes_dispersion, highly_variable_genes
 
Read more comments on GitHub >

github_iconTop Results From Across the Web

scanpy/api/pl.py "cannot import name stacked_violin ... - GitHub
I looked at the code and scanpy/apt/pl.py still has from ..plotting._anndata import scatter, violin, ranking, clustermap, stacked_violin, ...
Read more >
ImportError: cannot import name 'stacked_violin' from 'scanpy ...
This is definitely a bug in the module and seems like its stemming from the latest version that you must have upgraded to....
Read more >
scanpy.pl.stacked_violin — Scanpy 1.9.1 documentation
Makes a compact image composed of individual violin plots (from violinplot() ) stacked on top of each other. Useful to visualize gene expression...
Read more >
Clustering 3K PBMCs with Scanpy - Galaxy Training!
How to cluster cells in single-cell RNA-Seq data? How cell type annotation can be assigned to cell clusters? Objectives: Describe an AnnData object...
Read more >
scanpy · PyPI
Single-Cell Analysis in Python. ... Scanpy's plotting module can be viewed similar to Seaborn: an extension of matplotlib that allows visualizing operations ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found