vtraag / leidenalg

Implementation of the Leiden algorithm for various quality functions to be used with igraph in Python.
GNU General Public License v3.0
596 stars 78 forks source link

pip install issue version 0.8.2. (PEP 517 error) #49

Closed carloelle closed 3 years ago

carloelle commented 3 years ago

Hi, similarly to other users, I cannot install leidenalg version 0.8.2 due to an error for PEP 517. From my terminal:

`carloleonardi$ pip install leidenalg==0.8.2
Collecting leidenalg==0.8.2
  Using cached leidenalg-0.8.2.tar.gz (4.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: python-igraph>=0.8.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from leidenalg==0.8.2) (0.8.3)
Requirement already satisfied: texttable>=1.6.2 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from python-igraph>=0.8.0->leidenalg==0.8.2) (1.6.3)
Building wheels for collected packages: leidenalg
  Building wheel for leidenalg (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/c4/s69c9bcj2j5044vq4f7hh6gh0000gn/T/tmpz_t91kvw
       cwd: /private/var/folders/c4/s69c9bcj2j5044vq4f7hh6gh0000gn/T/pip-install-42ipj4km/leidenalg
  Complete output (56 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.9
  creating build/lib.macosx-10.9-x86_64-3.9/leidenalg
  copying src/functions.py -> build/lib.macosx-10.9-x86_64-3.9/leidenalg
  copying src/Optimiser.py -> build/lib.macosx-10.9-x86_64-3.9/leidenalg
  copying src/VertexPartition.py -> build/lib.macosx-10.9-x86_64-3.9/leidenalg
  copying src/version.py -> build/lib.macosx-10.9-x86_64-3.9/leidenalg
  copying src/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/leidenalg
  /private/var/folders/c4/s69c9bcj2j5044vq4f7hh6gh0000gn/T/pip-build-env-wfam4mxf/overlay/lib/python3.9/site-packages/setuptools/lib2to3_ex.py:36: SetuptoolsDeprecationWarning: 2to3 support is deprecated. If the project still requires Python 2 support, please migrate to a single-codebase solution or employ an independent conversion process.
    warnings.warn(
  Fixing build/lib.macosx-10.9-x86_64-3.9/leidenalg/functions.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/Optimiser.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/VertexPartition.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/version.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/__init__.py
  Skipping optional fixer: buffer
  Skipping optional fixer: idioms
  Skipping optional fixer: set_literal
  Skipping optional fixer: ws_comma
  Fixing build/lib.macosx-10.9-x86_64-3.9/leidenalg/functions.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/Optimiser.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/VertexPartition.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/version.py build/lib.macosx-10.9-x86_64-3.9/leidenalg/__init__.py
  Skipping optional fixer: buffer
  Skipping optional fixer: idioms
  Skipping optional fixer: set_literal
  Skipping optional fixer: ws_comma
  running build_ext
  running build_c_core
  Finding out version number/string... fatal: /private/var/folders/c4/s69c9bcj2j5044vq4f7hh6gh0000gn/T/pip-install-42ipj4km/leidenalg/vendor/source/igraph/../../../.git/modules/vendor/source/igraph non è un repository Git
  fatal: /private/var/folders/c4/s69c9bcj2j5044vq4f7hh6gh0000gn/T/pip-install-42ipj4km/leidenalg/vendor/source/igraph/../../../.git/modules/vendor/source/igraph non è un repository Git
  -post+
  + /usr/local/bin/glibtoolize --force --copy
  glibtoolize: putting auxiliary files in '.'.
  glibtoolize: copying file './ltmain.sh'
  glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
  glibtoolize: copying file 'm4/libtool.m4'
  glibtoolize: copying file 'm4/ltoptions.m4'
  glibtoolize: copying file 'm4/ltsugar.m4'
  glibtoolize: copying file 'm4/ltversion.m4'
  glibtoolize: copying file 'm4/lt~obsolete.m4'
  + aclocal -I m4 --install
  bootstrap.sh: line 27: aclocal: command not found
  + autoheader
  bootstrap.sh: line 28: autoheader: command not found
  + autoconf
  bootstrap.sh: line 29: autoconf: command not found
  + automake --foreign --add-missing --force-missing --copy
  bootstrap.sh: line 31: automake: command not found
  + patch -N -p0 -r-
  sh: ../../source/igraph/configure: No such file or directory
  We are going to build the C core of igraph.
    Source folder: vendor/source/igraph
    Build folder: vendor/build/igraph
    Install folder: vendor/install/igraph

  Bootstrapping igraph...
  Configuring igraph...
  Could not compile the C core of igraph.

  ----------------------------------------
  ERROR: Failed building wheel for leidenalg
Failed to build leidenalg
ERROR: Could not build wheels for leidenalg which use PEP 517 and cannot be installed directly`

Note that I am able to install leidenalg version 0.7.0. (but when I ran it through Seurat in R, it cannot find leiden algorithm:

FindClusters(PDAC.subset, resolution = 1e-4,algorithm=4, method="igraph") Error: Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).

igraph is already installed (igraph 0.8.3 running inside Python 3.9.0).

since PEP 517 errors are a common issue (see https://github.com/pydata/bottleneck/issues/281 ), I tried to install anaconda and install leidenalg through anaconda, but still in R Seurat does not recognize it, returning the same error (Cannot find Leiden algorithm). I also tried to install Visual Studio as someone suggested (since it should update all the wheels), but it doesn't work again.

Any idea how to proceed?

vtraag commented 3 years ago

Unfortunately there are not yet binary wheels available for Python 3.9 from PyPI, but there are binaries available for Python 3.8. Could you perhaps try to use Python 3.8 instead (at least for the time being)?

You could try to install using the --no-use-pep517 option? You will need to install also build dependencies though (see https://igraph.org/python/#pycompile for details).

carloelle commented 3 years ago

So, --no-use-pep517 using Python3.9 (and also python2.7, the reason I updated to the last version of python) resulted in the same error. Though installing python3.8 fixed this issue and Leidenalg 0.8.2. is successfully installed.

Still, in R using Seurat, if I run FindClusters(x, resolution = 1e-4, algorithm=4 (4 corresponds to Leiden alg.) it returns the error Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).

since I have multiple versions of python installed, do you know if Seurat 3.2.2 is referring to a particular python version in which it's looking for leidenalg?

vtraag commented 3 years ago

Sorry, I don't know how to solve the Seurat dependency immediately. Probably @TomKellyGenetics could be of help here.

carloelle commented 3 years ago

Resolved: use the reticulate package to define which python version to use (at the beginning of the r session). for more info: https://rstudio.github.io/reticulate/reference/use_python.html

TomKellyGenetics commented 3 years ago

To clarify, calling leidenalg with the 'leiden' R package or in 'Seurat' just requires any version of leidenalg to be installed in Python. In principle, it should be able to run if any Python version is installed. My current working uses Python 3.7.3 but as long as the arguments passes haven't been changed in leidenalg it should work (definitely no need to use Python 2 but it should be supported). Note that Seurat (optionall) runs other functions (e.g., UMAP) through Python with reticulate also have the should be supported by the same Python version.

I recommend using a conda environment with "reticulate" but a pip install should be possible, provided you direct R to the same version of python.

frankchen121212 commented 2 years ago

Hello, followed by carloelle , I've solved this issue, Here are some detailed scripts:

First, module load anaconda3 Then create your virtual environment: your_env After activating the environment: source activate your_env: pip install leidenalg

Then deactivate the environment

Then in your R script:

dt.seurat <- FindNeighbors(dt.seurat, dims = 1:20, verbose = 0) use_condaenv(condaenv = "your_env", required = TRUE) py_run_string('import leidenalg') dt.seurat <- FindClusters(dt.seurat, resolution = 0.1, algorithm=4, method="igraph") dt.seurat <- RunUMAP(dt.seurat,dims = 1:20, metric="correlation")