ku-cbd / PhageBoost

Rapid discovery of novel prophages using biological feature engineering and machine learning
GNU General Public License v3.0
35 stars 6 forks source link

Python error after installation #31

Open shaman-narayanasamy opened 10 months ago

shaman-narayanasamy commented 10 months ago

Dear authors/developers,

I am unable to execute PhageBoost after installation via conda + pip. Here are the command I issued:

$ conda env remove -n phageboost
$ conda create -y -n phageboost python=3.7
$ conda activate phageboost
$ pip install PhageBoost
(no obvious error/warnings)
$ PhageBoost -h
Traceback (most recent call last):
  File "/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/bin/PhageBoost", line 5, in <module>
    from PhageBoost.main import main
  File "/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/lib/python3.7/site-packages/PhageBoost/__init__.py", line 1, in <module>
    from PhageBoost import get_genecalls, get_predictions, get_matches, calc_features, main, bbcache
  File "/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/lib/python3.7/site-packages/PhageBoost/bbcache.py", line 6, in <module>
    from cachier import cachier
  File "/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/lib/python3.7/site-packages/cachier/__init__.py", line 1, in <module>
    from .core import (
  File "/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/lib/python3.7/site-packages/cachier/core.py", line 20, in <module>
    from typing import TYPE_CHECKING, Callable, Literal, Optional, TypedDict, Union
ImportError: cannot import name 'Literal' from 'typing' (/Users/shaman.narayanasamy/opt/miniconda3/envs/phageboost/lib/python3.7/typing.py)

I tested it on two independent systems, both resulting in the same error. I also skimmed though the current open and closed issues on the github but could not find anything related to this issue. I would appreciate your help in solving this issue.

I look forward to hearing from you.

Best regards, Shaman

danzheng7372 commented 8 months ago

Hi, did you find the solution? I have the same problem.

naturepoker commented 8 months ago

Just writing to add I have the same issue as well - conda environment with python version 3.7, along with

conda install xgboost=1.0.2

Tried both regular pip install within the environment as well as cloning from the github repository and installing directly.

shaman-narayanasamy commented 8 months ago

Hi, did you find the solution? I have the same problem.

Hi! No, I have not found a solution.

gwickh commented 7 months ago

Hi folks, I've made some progress on getting this working.

There are more downstream compatibility issues with XGBoost and Pyrodigal which can be resolved by cloning PhageBoost from Git and rolling dependencies back with

   conda create -y -n PhageBoost-env python=3.7
   conda activate PhageBoost-env
   pip3 install typing_extensions
   pip install pyrodigal==0.7.2 xgboost==1.0.2 git+https://github.com/ku-cbd/PhageBoost

The literal import error is resolved by installing typing_extensions and editing line20 of miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/core.py from

     from typing import TYPE_CHECKING, Callable, Literal, TypedDict, Optional,  Union

to

    from typing import TYPE_CHECKING, Callable,  Optional,  Union
    from typing_extensions import Literal, TypedDict

PhageBoost then successfully executes

   PhageBoost -f PS18CH-0305-5_contigs.fa -o . -c 1000 --threads 15

   processing: PS18CH-0292-1_contigs
   time after genecalls: 101.34925127029419 
   time after feature calculations: 126.40964388847351
   time after predictions: 128.9284040927887
   {'phage22': 50, 'phage4': 48, 'phage11': 48, 'phage0': 32, 'phage15': 29, 'phage14': 28, 'phage3': 19, 'phage21': 19, 
   'phage12': 18, 'phage1': 18, 'phage10': 16, 'phage18': 15, 'phage19': 14, 'phage13': 12, 'phage8': 11, 'phage20': 10, 
   'phage7': 10, 'phage23': 10}

Hope this helps some people

danzheng7372 commented 7 months ago
pip install pyrodigal==0.7.2 xgboost==1.0.2 git+https://github.com/ku-cbd/PhageBoost

Hi gwickh, Thank you very much for the solution! I have tried to fix it, but I found something different in my installation. So in my core.py file, I could only find this in Line17 of "miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/core.py ", from typing import Optional, Union. Then I also revised this line as from typing import TYPE_CHECKING, Callable, Optional, Union from typing_extensions import Literal, TypedDict Here are the command I issued: (PhageBoost-env) wet@brl:~$ PhageBoost -h Traceback (most recent call last): File "/home/wet/miniconda3/envs/PhageBoost-env/bin/PhageBoost", line 5, in from PhageBoost.main import main File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/PhageBoost/init.py", line 1, in from PhageBoost import get_genecalls, get_predictions, get_matches, calc_features, main, bbcache File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/PhageBoost/bbcache.py", line 6, in from cachier import cachier File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/init.py", line 2, in from .config import ( File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py", line 5, in from typing import Optional, TypedDict, Union ImportError: cannot import name 'TypedDict' from 'typing' (/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/typing.py)

Do you have any suggestions? I have been frustrated by the installation of phageboost for several weeks. Thank you very much for the help!

gwickh commented 7 months ago

Based on this

File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py", line 5, in
from typing import Optional, TypedDict, Union

You should go into /home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py and change

from typing import Optional, TypedDict, Union

to

from typing import Optional, Union
from typing_extensions import TypedDict

Let me know if it works!

danzheng7372 commented 7 months ago

Based on this

File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py", line 5, in
from typing import Optional, TypedDict, Union

You should go into /home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py and change

from typing import Optional, TypedDict, Union

to

from typing import Optional, Union
from typing_extensions import TypedDict

Let me know if it works!

Hi, thank you for the prompt reply. I have tried again but seemed like more errors in config.py and typing.py. Here are the command I issued: (PhageBoost-env) wet@brl:~$ PhageBoost -h Traceback (most recent call last): File "/home/wet/miniconda3/envs/PhageBoost-env/bin/PhageBoost", line 5, in from PhageBoost.main import main File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/PhageBoost/init.py", line 1, in from PhageBoost import get_genecalls, get_predictions, get_matches, calc_features, main, bbcache File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/PhageBoost/bbcache.py", line 6, in from cachier import cachier File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/init.py", line 2, in from .config import ( File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py", line 8, in from ._types import Backend, HashFunc, Mongetter File "/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/_types.py", line 1, in from typing import TYPE_CHECKING, Callable, Literal ImportError: cannot import name 'Literal' from 'typing' (/home/wet/miniconda3/envs/PhageBoost-env/lib/python3.7/typing.py)

gwickh commented 7 months ago

Are you able to tell me which Python 3.7 release you are using? Python 3.7.12 doesn't seem to raise that error

danzheng7372 commented 7 months ago

Hi, I have checked that I am using the Python 3.7.12 release. Thank you very much for the following.

Screenshot 2024-03-15 at 18 02 04
danzheng7372 commented 7 months ago

Hi, I solved this problem based on the solution provided by [gwickh]. Thank you very much for the help and guidance!

So in my case, I revised two files. (1) miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/config.py, change from typing import Optional, Union, TypedDict to from typing import Optional, Union and from typing_extensions import TypedDict (2) miniconda3/envs/PhageBoost-env/lib/python3.7/site-packages/cachier/_types.py, change from typing import TYPE_CHECKING, Callable, Literal to from typing import TYPE_CHECKING, Callable and from typing_extensions import Literal

Hope this helps some people with the same errors.

AndAvia commented 2 months ago

@danzheng7372 Solved my problem ImportError: cannot import name 'TypedDict' from 'typing' (/data4/machuang/miniconda3/envs/phageboost/lib/python3.7/typing.py)
Here is my installation process, conda create -y -n phageboost python=3.7 conda activate phageboost

In China you can use accelerated with Tsinghua Mirror

pip install pyrodigal==0.6.4 xgboost==1.0.2 typing_extensions PhageBoost --index-url https://pypi.tuna.tsinghua.edu.cn/simple

Modify the following files

(1) miniconda3/envs/phageboost/lib/python3.7/site-packages/cachier/config.py, changefrom typing import Optional, Union, TypedDict to from typing import Optional, Union and from typing_extensions import TypedDict (2) miniconda3/envs/phageboost/lib/python3.7/site-packages/cachier/_types.py, changefrom typing import TYPE_CHECKING, Callable, Literal to from typing import TYPE_CHECKING, Callable and from typing_extensions import Literal

At last

PhageBoost -h

Running the test file will still report an error KeyError: 'X' It is possible to use GitHub version git clone https://github.com/ku-cbd/PhageBoost.git cd PhageBoost pip install . Then run PhageBoost -f example/data/NC_000907.fasta.gz -o results You'll get processing: NC_000907 time after genecalls: 1.2304344177246094 time after feature calculations: 5.240534067153931 time after predictions: 7.159439563751221 {'phage6': 51, 'phage5': 26}

danzheng7372 commented 2 months ago

Good to konw that it works! @AndAvia