HallLab / pandas-genomics

Pandas ExtensionDtypes for dealing with genomics data
BSD 3-Clause "New" or "Revised" License
47 stars 8 forks source link

numpy.core.multiarray failed to import #32

Closed disadone closed 1 year ago

disadone commented 1 year ago

While running the example

from pandas_genomics.scalars import Variant
from pandas_genomics.arrays import GenotypeArray
variant = Variant('12', 112161652, id='rs12462', ref='A', alt=['C'])
gt_array = GenotypeArray([variant.make_genotype_from_str(s) for s in ["C/C", "A/C", "A/A"]])

It reports

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem .
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-16-0cf2f396ab63>](https://localhost:8080/#) in <cell line: 2>()
      1 from pandas_genomics.scalars import Variant
----> 2 from pandas_genomics.arrays import GenotypeArray
      3 variant = Variant('12', 112161652, id='rs12462', ref='A', alt=['C'])
      4 gt_array = GenotypeArray([variant.make_genotype_from_str(s) for s in ["C/C", "A/C", "A/A"]])

10 frames
[/usr/local/lib/python3.10/dist-packages/numpy/testing/_private/utils.py](https://localhost:8080/#) in <module>
     21 from numpy.core import(
     22      intp, float32, empty, arange, array_repr, ndarray, isnat, array)
---> 23 import numpy.linalg.lapack_lite
     24 
     25 from io import StringIO

ImportError: numpy.core.multiarray failed to import

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

run on google colab and install pandas-genomics using pypi and github

AndreRicoPSU commented 1 year ago

Dear Xiaodong,

It looks like there are two issues here: a C-API incompatibility error and a numpy import error.

Regarding the C-API incompatibility error, the error message suggests that the numpy version being used is not compatible with the version that the pandas-genomics module was compiled against. You can try to solve this by following the instructions in the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility. Specifically, you can try upgrading numpy to the latest version by running pip install --upgrade numpy. If that doesn't work, you can try downgrading numpy to the version specified in the error message by running `pip install numpy==1.24.3 (the latest version validated with Pandas-Genomics).

Another alternative I encourage you to pursue is to create a new virtual environment with your own Python 3.10 installation, install Pandas-Genomics (which will automatically install Numpy as a dependency), and check if your script runs successfully within that environment.

To create a new virtual environment, you can follow these steps:

  1. Install virtualenv if you don't have it already by running pip install virtualenv in your terminal or command prompt.
  2. Create a new folder where you want to host the virtual environment.
  3. Navigate to that folder in your terminal or command prompt.
  4. Create a new virtual environment by running virtualenv venv --python=python3.10.
  5. Activate the virtual environment by running source venv/bin/activate on Linux/Mac or venv\Scripts\activate on Windows.
  6. Install Pandas-Genomics by running pip install pandas-genomics.
  7. Run your script within the virtual environment and check if it runs without errors.

Please feel free to ask any further questions or share your success in running Pandas-Genomics.

Andre

image